这个查询有什么问题? 无法让 ROW_NUMBER() 工作
SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY hrl.Frn) as Row,
hrl.unq, hrl.LcnsId, hc.Business,hc.Name,hc.Phone,
hrl.Frn,hrl.CallSign, hrl.gsamarkettypeid,
gmt.[Market Type Code] + ' - ' + gmt.gsamarkettype,
hrl.gsalatitude,hrl.gsalongitude,
rsc.RadioServiceCode + ' - ' + rsc.RadioService,
GrantDt, ExpirationDt, EffectiveDt,
CancellationDt
FROM dbo.sbi_f_HldrRgstrtnLcns hrl
INNER JOIN dbo.sbi_f_HldrCntcts hc on
hc.CallSign = hrl.CallSign
INNER JOIN dbo.sbi_l_radioservicecodes rsc on
rsc.radioservicecodeid = hrl.radioservicecodeid
LEFT OUTER JOIN dbo.sbi_l_GSAMarketTypes gmt on
gmt.GSAMarketTypeId = hrl.GSAMarketTypeId
WHERE hc.Entity_Type = 'L' AND hrl.LicenseStatusId IN (1)
and Row >=1 and Row <= 20) -- The error occurs here,
-- it says incorrect syntax near )
SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY hrl.Frn) as Row,
hrl.unq, hrl.LcnsId, hc.Business,hc.Name,hc.Phone,
hrl.Frn,hrl.CallSign, hrl.gsamarkettypeid,
gmt.[Market Type Code] + ' - ' + gmt.gsamarkettype,
hrl.gsalatitude,hrl.gsalongitude,
rsc.RadioServiceCode + ' - ' + rsc.RadioService,
GrantDt, ExpirationDt, EffectiveDt,
CancellationDt
FROM dbo.sbi_f_HldrRgstrtnLcns hrl
INNER JOIN dbo.sbi_f_HldrCntcts hc on
hc.CallSign = hrl.CallSign
INNER JOIN dbo.sbi_l_radioservicecodes rsc on
rsc.radioservicecodeid = hrl.radioservicecodeid
LEFT OUTER JOIN dbo.sbi_l_GSAMarketTypes gmt on
gmt.GSAMarketTypeId = hrl.GSAMarketTypeId
WHERE hc.Entity_Type = 'L' AND hrl.LicenseStatusId IN (1)
and Row >=1 and Row <= 20) -- The error occurs here,
-- it says incorrect syntax near )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将您的行条件移动到外部选择中
Move your Row criteria into the outer select
您可以使用 CTE 来做到这一点:
You could do this using a CTE:
检查您使用的是哪个版本的 sql server 数据库。 row_number 是从 sql server 2005 开始添加的。 它不支持sql server 2000
check which version of sql server database are you using. The row_number is added from sql server 2005 onwards. It will not support sql server 2000
不能对 where 子句中的列使用别名,因为 where 子句是在 Select 子句之前处理的。
编辑:
您也可以只在 where 子句中添加子查询,
或者根本不使用 Row_Number,
You can't use an alias for a column in a where clause, because the where clause is processed before the Select Clause.
EDITED:
You could also just add the subquery in the where clause
or without usingt Row_Number at all,