表的每一行都是一个带有日期和字节的应用程序(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的任何想法?谢谢!
答案 0 :(得分:1)
您可以使用order by total desc and date 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
答案 1 :(得分:1)
您的样本数据提示我:
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;