共计 774 个字符,预计需要花费 2 分钟才能阅读完成。
面试问到的希望对各位仁兄有所帮助,记录一些日常小知识
首先是一个数据表
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)
正文完