Mysql中的MSSQL Row_Number()over(order by)
我需要使用以下查询创建group by子句:
SELECT NAME, SUM(donationvalue) FROM tbl_pdm2k10_DonationsGROUP 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
这可能吗?
回答:
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
以上是 Mysql中的MSSQL Row_Number()over(order by) 的全部内容, 来源链接: utcz.com/qa/420154.html