我有下表-

mysql> select * from appdata;
+------------+----------+-----------+
| timestamp  | appName  | Bytes     |
+------------+----------+-----------+
| 1454169299 | DNS      |    123456 |
| 1454169292 | DNS      |     12342 |
| 1454169292 | Facebook |   1234222 |
| 1454169297 | Youtube  | 123422233 |
+------------+----------+-----------+

I wanted to sum the byte and show the single application and consumed bytes


我执行了

mysql> select appName,Sum(Bytes) from appdata group by appName;
+----------+------------+
| appName  | Sum(Bytes) |
+----------+------------+
| DNS      |     135798 |
| Facebook |    1234222 |
| Youtube  |  123422233 |
+----------+------------+


现在我想运行一个查询,使我得到消耗更多字节的应用程序

youtube  123422233
Facebook 1234222
DNS 135798


我在跑步

select appName,Sum(Bytes) from appdata group by appName
    (select appName,Bytes FROM appdata ORDER BY Bytes desc limit 3);


但是它不起作用,请让我知道我该如何实现。

谢谢。

最佳答案

尝试这个:

SELECT appname, SUM(bytes) FROM appdata GROUP BY appname ORDER BY SUM(bytes) DESC LIMIT 3;

您需要按字节总数的降序进行排序,这样您将首先获得最高的数字。

关于mysql - SQL上的多选查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35343969/

10-12 07:16