MySQL statistics shows that the order in a table is greater than a certain value

Time:2019-12-2

I hope the interview will help you, and record some daily knowledge

First is a data table
mysql> select * from order_list;
+------------+--------+-------+---------------------+
| id         | name   | price | data                |
+------------+--------+-------+---------------------+
|2019101301 | Li Yao | 199 | 2019-10-13 17:24:34|
|2019101302 | Wang Ting | 99 | October 13, 2019 17:27:34|
|201910303 | Li Yao | 299 | 2019-10-13 17:32:34|
|2019101304 | Wang Lei | 89 | 2019-10-13 17:39:18|
|2019101305 | Zhao Yang | 39 | 2019-10-13 17:24:34|
|2019101306 | Zhao Yang | 69 | 2019-10-13 17:39:19|
+------------+--------+-------+---------------------+
6 rows in set (0.00 sec)

Write a list of SQL output consumption greater than 89 that day
SELECT SUM(price),name FROM order_list GROUP BY name HAVING SUM(price)>89 ;

The results are as follows:

mysql> SELECT SUM(price),name FROM order_list GROUP BY name HAVING SUM(price)>89 ;
+------------+--------+
| SUM(price) | name   |
+------------+--------+
|498 Li Yao|
|99 Wang Ting|
|108 Zhao Yang|
+------------+--------+
3 rows in set (0.00 sec)

Recommended Today

ASP.NET Example of core MVC getting the parameters of the request

preface An HTTP request is a standard IO operation. The request is I, which is the input; the responsive o is the output. Any web development framework is actually doing these two things Accept the request and parse to get the parameters Render according to the parameters and output the response content So let’s learn […]