分页且按总分排序,分页且按总分排序
DECLARE @SQL VARCHAR(5000) SET @SQL =' SELECT top '+Convert(varchar(4),20)+' a.pro_id,a.pro_title,convert(decimal(18,2),(sum(convert(decimal(18,2),b.praise_xjbscore)))/count(praise_id)) as zf from p_product A left join p_praise b on pro_id=praise_pro where pro_id not in (select top ' + cast((20*(convert(Int,1)-1)) as varchar(10))+' a.pro_id,convert(decimal(18,2),(sum(convert(decimal(18,2),b.praise_xjbscore)))/count(praise_id)) as zf from p_product a left join p_praise b on pro_id=praise_pro where 1=1 group by a.pro_id order by zf desc) group by a.pro_id,a.pro_title order by zf desc' EXECUTE (@SQL)
当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式。如何解决了
[解决办法]
你这样写太麻烦了,
现在有Row_Number()函数可以生成行号,然后通过等号用between and 不就可以得到你想要的结果吗?
类似的,先做个子查询:
select *,Row_Number() over(order by name) rn
from tb
你试一下