按评估字段分组(sql server)

时间:2017-03-06 21:12:22

标签: sql-server

关于SQL Server“group by”子句,以下SQL语句有效:

select
  convert(datetime,ROUND(convert(float,InHistoryDate),0)) as date,
  Payername as clientname,
  SUM(COALESCE(CAST(NULLIF(ISNUMERIC(TotalCharge), 1) AS MONEY), TotalCharge)) as total_char,
  SUM(COALESCE(CAST(NULLIF(ISNUMERIC(HCPSaving), 1) AS MONEY), HCPSaving)) as savings,
  SUM(1) as claims
from EquianClaimSystem.dbo.LongHCFA1500BMHistory
group by InHistoryDate, Payername
order by 1

以下SQL语句不起作用:

select
  convert(datetime,ROUND(convert(float,InHistoryDate),0)) as date,
  Payername as clientname,
  SUM(COALESCE(CAST(NULLIF(ISNUMERIC(TotalCharge), 1) AS MONEY), TotalCharge)) as total_char,
  SUM(COALESCE(CAST(NULLIF(ISNUMERIC(HCPSaving), 1) AS MONEY), HCPSaving)) as savings,
  SUM(1) as claims
from EquianClaimSystem.dbo.LongHCFA1500BMHistory
group by 1, 2
order by 1

为什么我不能在group by子句中使用数字来引用字段的评估结果而不是SQL Server中的直接字段名称?

有解决方法吗?

0 个答案:

没有答案