gpt4 book ai didi

php - SELECT月度记录表数据库

转载 作者:搜寻专家 更新时间:2023-10-30 21:43:49 25 4
gpt4 key购买 nike

mysql> SELECT * FROM con_transactions;
+------+------+---------------------+--------+
| t_id | p_id | date | amount |
+------+------+---------------------+--------+
| 10 | 1 | 2016-02-17 19:24:05 | 1800 |
| 12 | 2 | 2016-02-18 11:40:13 | 200 |
| 17 | 3 | 2016-02-18 11:42:04 | 100 |
| 19 | 4 | 2016-02-18 11:45:43 | 1 |
| 20 | 5 | 2016-02-18 11:45:54 | 999 |
| 21 | 1 | 2016-02-18 11:46:02 | 1500 |
| 41 | 2 | 2016-02-18 17:23:14 | 500 |
| 42 | 3 | 2016-02-18 17:23:14 | 500 |
| 43 | 4 | 2016-02-18 17:23:15 | 500 |
| 44 | 5 | 2016-02-18 17:23:16 | 500 |
| 45 | 1 | 2016-02-18 17:23:16 | 500 |
| 46 | 2 | 2016-02-18 17:23:16 | 500 |
| 47 | 3 | 2016-02-18 17:23:17 | 500 |
| 48 | 4 | 2016-02-18 17:23:17 | 500 |
| 49 | 5 | 2016-02-18 17:23:18 | 500 |
| 50 | 1 | 2016-02-18 17:25:54 | 1000 |
| 51 | 1 | 2016-02-18 17:26:22 | 3000 |
| 52 | 2 | 2016-02-18 17:48:59 | 10 |
| 53 | 1 | 2016-02-18 17:48:59 | 10 |
| 55 | 1 | 2016-02-19 10:20:12 | 1000 |
+------+------+---------------------+--------+

如何选择当前月份或上个月的所有交易记录。所有月份都不是 30 天。那么如何使用 SELECT 查询选择一月或其他月份的记录。我试试这个查询

SELECT * FROM con_transactions WHERE date > '2016-01-01 00:00:00' AND date < '2016-02-01 00:00:00';

这不是那么聪明。

最佳答案

使用 month()year() 直接查找一年中的任何给定月份。

SELECT * FROM con_transactions WHERE year(date)  = 2016 AND month(date) = 1;

关于php - SELECT月度记录表数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35504755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com