sql - 从嵌套选择 T-SQL 中选择

标签 sql sql-server tsql

我希望通过在内部查询中选择数据来修改数据 并计算其中之一已修改.. 它给出了错误..

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
)

最佳答案

您需要为子查询指定别名:

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

关于sql - 从嵌套选择 T-SQL 中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6988220/

相关文章:

sql-server - 如何在没有桌面的情况下在 Vagrant 中安装 SQL Server Express 2014?

sql - SQL Server 中的递归查询问题

sql - 使用动态 SQL 设置参数

sql - 如何使用简单的 Join 语句更新具有不同值的列?

c# - 如果在 C# 中失败,则回滚 sql 事务

sql - Oracle 中使用 TO_CHAR 进行数字格式化

c# - 表锁抛出异常 vs 表锁等待结束

c# - 如何在一个元素(Gridview)上绑定(bind)多个数据?

java - 删除数据库表中所有事件的大型 txt 文件中的数据

mysql - 删除除最后 10 行之外的所有行?或者最大行数 = 10?