我需要使用以下查询创建group by子句:
SELECT NAME, SUM(donationvalue) FROM tbl_pdm2k10_Donations
GROUP BY NAME
ORDER BY SUM(donationvalue) desc
但是我想要左边的一列回复我:结果是1,2,3,4,5等。 在MSSql中我会做
SELECT Row_Number() Over(order by SUM(donationvalue) desc), NAME, SUM(donationvalue)
FROM tbl_pdm2k10_Donations
GROUP BY NAME
这可能吗?
答案 0 :(得分:4)
set @row:=0;
SELECT
@row:=@row+1 as row_numer,
NAME,
SUM(donationvalue) as total
FROM tbl_pdm2k10_Donations
GROUP BY NAME
ORDER BY total desc
答案 1 :(得分:1)