我的表格的每一行都是一个带有日期和字节的应用程序(google、facebook)。
我正在做的是根据此请求按应用程序和日期进行分组:
SELECT app, sum(bytes) as total, date
FROM logs
WHERE `date` BETWEEN '2018-11-23' AND '2018-11-25'
GROUP BY app, date
这是结果:
app | total | date
facebook | 2736 | 2018-11-23
google | 4968 | 2018-11-23
twitter | 606520 | 2018-11-23
facebook | 2736 | 2018-11-24
youtube | 153077 | 2018-11-24
twitter | 84561 | 2018-11-24
但我需要的是在 DESC 中订购总计。所以现在我尝试每天按总数排序并得到以下结果:
app | total | date
twitter | 606520 | 2018-11-23 <---
google | 4968 | 2018-11-23 <---
facebook | 2736 | 2018-11-23
youtube | 153077 | 2018-11-24 <---
twitter | 84561 | 2018-11-24 <---
facebook | 2736 | 2018-11-24
知道如何使用 mysql 做到这一点吗?谢谢!
最佳答案
您可以尝试使用以下命令按总 desc 和日期 asc 排序
SELECT app, sum(bytes) as total, date
FROM logs
WHERE `date` BETWEEN '2018-11-23' AND '2018-11-25'
GROUP BY app, date
order by date,total desc
关于mysql - SQL如何先按天排序,然后按总和排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53831667/