如何基于总收入(net_ph)获得排名?

问题描述 投票:-1回答:1

Here's the output i want, you can see i have rank columns in excel

上面的图像是我想要的输出,我希望它具有基于'净收入总计(net_ph)'的排名

PHP中的我的代码

SELECT artist, label, SUM(net_ph) as net_ph from believe_tb where  accounts_of='$cid2' group by artist, label

查询输出(无排名)enter image description here

mysql sql
1个回答
0
投票

您可以使用如下查询:

选择艺术家,标签,RANK()OVER(按ORDER BY SUM(net_ph)desc)作为排名,SUM(net_ph)作为net_ph,来自artist_tb,按艺术家,标签分组;

希望这会有所帮助。有关RANK()函数的更多信息:https://www.mysqltutorial.org/mysql-window-functions/mysql-rank-function/

© www.soinside.com 2019 - 2024. All rights reserved.