MSSQL Row_Number() over(order by) 在 MySql 中

2022-01-01 00:00:00 sql-server-2005 mysql

我需要使用以下查询创建一个 group by 子句:

i need to make a group by clause with the following query:

SELECT NAME, SUM(donationvalue) FROM tbl_pdm2k10_Donations
GROUP BY NAME
ORDER BY SUM(donationvalue) desc

但我想要左边的一列返回我:1、2、3、4、5 等作为结果.在 MSSql 我会做

but i want a column on the left returning me: 1, 2, 3, 4, 5, etc as as result. In MSSql i would do

  SELECT Row_Number() Over(order by SUM(donationvalue) desc), NAME, SUM(donationvalue)      
 FROM tbl_pdm2k10_Donations
    GROUP BY NAME

这可能吗?

推荐答案

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

相关文章