我正在SQL中运行此查询:
select
--CLAIM_ID,
--sum (paid_amount),
(ROW_NUMBER() OVER (partition by claim_id order BY claim_id) as asdf)
from [FRAUD].[dbo].[MU_GAPA_ADS_CLAIM_ANALYSIS_ALLACCOUNTS]
where (ALTGRP like '48000%') and (svcDAT between '10/01/2016' and '10/01/2016')
Group By claim_id
但是,我听到以下错误消息:
第156条消息,级别15,状态1,第4行 关键字“ as”附近的语法不正确。
有人可以帮助我了解发生了什么以及如何解决吗?
谢谢。
答案 0 :(得分:2)
问题不是row_number()
。问题是列别名周围的括号:
ROW_NUMBER() OVER (partition by claim_id order BY claim_id) as asdf
您还应该修复日期常数:
select CLAIM_ID, sum(paid_amount),
row_number() over (partition by claim_id order by claim_id) as asdf)
from [FRAUD].[dbo].[MU_GAPA_ADS_CLAIM_ANALYSIS_ALLACCOUNTS]
where ALTGRP like '48000%' and
svcDAT between '2016-10-01' and '2016-10-01'
Group By claim_id;
总而言之,row_number()
总是会为该查询返回“ 1”,因此您最好将其省略。