mysql统计一个表中订单大于某个数值

面试问到的希望对各位仁兄有所帮助,记录一些日常小知识

首先是一个数据表
mysql> select * from order_list;
+------------+--------+-------+---------------------+
| id         | name   | price | data                |
+------------+--------+-------+---------------------+
| 2019101301 | 李姚   |   199 | 2019-10-13 17:24:34 |
| 2019101302 | 王婷   |    99 | 2019-10-13 17:27:34 |
| 2019101303 | 李姚   |   299 | 2019-10-13 17:32:34 |
| 2019101304 | 王磊   |    89 | 2019-10-13 17:39:18 |
| 2019101305 | 赵杨   |    39 | 2019-10-13 17:24:34 |
| 2019101306 | 赵杨   |    69 | 2019-10-13 17:39:19 |
+------------+--------+-------+---------------------+
6 rows in set (0.00 sec)

写一条sql 输出当天消费大于89的名单
SELECT SUM(price),name FROM order_list GROUP BY name HAVING SUM(price)>89 ;

结果如下:

mysql> SELECT SUM(price),name FROM order_list GROUP BY name HAVING SUM(price)>89 ;
+------------+--------+
| SUM(price) | name   |
+------------+--------+
|        498 | 李姚   |
|         99 | 王婷   |
|        108 | 赵杨   |
+------------+--------+
3 rows in set (0.00 sec)

你可能感兴趣的:(sql)