[英]MySQL get records by quarters
Have problem to returning results from MySQL by quarters. 按季度从MySQL返回结果有问题。
Mysql: id
, start_datetime
, end_datetime
and more columns. Mysql:
id
, start_datetime
, end_datetime
和更多列。
I need to return records by start_datetime (for example it's - 2016-03-05 20:12:22
| MySQL column format is DateTime). 我需要按start_datetime返回记录(例如
2016-03-05 20:12:22
| MySQL列格式为DateTime)。 How can I write MySQL query to display that record in a specific quarter? 如何编写MySQL查询以显示特定季度的记录?
I was searching a lot but didn't find anything that would work fo me: I tested this: 我进行了很多搜索,但没有找到对我有用的东西:我对此进行了测试:
SELECT * FROM appointments
WHERE id_user = 80
AND DATE_SUB(start_datetime, INTERVAL 1 QUARTER)
AND hash = 'completed'
But it's not working correct. 但这不能正常工作。
This will give you the results for quarter 1: 这将为您提供第一季度的结果:
SELECT * FROM appointments
WHERE id_user = 80
AND QUARTER(start_datetime) = 1
AND hash = 'completed'
Change the "1" to 2, 3, or 4 to get the other quarters 将“ 1”更改为2、3或4以获取其他四分之一
Here is the way to get all the data based on quarter inMySql or WordPress. 这是基于季度inMySql或WordPress获取所有数据的方法。
Note : visited is the datetime column into the table 注意:访问的是表中的datetime列
QUARTER(your date)
will give you the current quarter. QUARTER(your date)
将为您提供当前季度。
Previous Quarter
上一季度
SELECT * FROM tbl_users WHERE QUARTER(visited) = QUARTER(curdate() - INTERVAL 1 quarter)
Current Quarter
当前季度
SELECT * FROM tbl_users WHERE QUARTER(visited) = QUARTER(curdate())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.