从嵌套选择 T-SQL 中选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6988220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Select from nested select T-SQL
提问by zapoo
I wish to modify data by selecting them in a inner query and count one of them modified.. It gives error..
我希望通过在内部查询中选择数据来修改数据,并计算其中一个已修改.. 它给出了错误..
select count(cvs) from
(
select
cvs,
(case Citycode when 123 then 'test' else 'other' end) as CityName ,
(case ProductCode when '000' then 'test3' when 'ss' then 'xtr' else 'ddd' end) as CardName
from Applications
)
回答by Dalen
you need to give an alias to the subquery:
您需要为子查询提供别名:
select count(x.cvs) from
(
select
cvs,
(case Citycode when 123 then 'test' else 'other' end) as CityName ,
(case ProductCode when '000' then 'test3' when 'ss' then 'xtr' else 'ddd' end) as CardName
from Applications
) x
回答by Joe Stefanelli
Why not just do this instead?
为什么不这样做呢?
SELECT COUNT(cvs)
FROM Applications
回答by JNK
Two things I see off the bat:
我看到了两件事:
1 - You don't need the nested subquery for what you are doing in the example. You could just as easily do:
1 - 您不需要嵌套子查询来执行示例中的操作。你可以很容易地做到:
SELECT COUNT(cvs) FROM application
SELECT COUNT(cvs) FROM application
2 - You need an alias for the subquery, like (<subquery>) as SubQ
2 - 您需要子查询的别名,例如 (<subquery>) as SubQ
回答by Quintin Robinson
It appears your query could be simplified to..
看来您的查询可以简化为..
SELECT COUNT(cvs) FROM Applications
Is there a reason you have the select nested and you are ignoring the other columns being selected?
您是否有选择嵌套的原因而忽略了其他被选中的列?