gpt4 book ai didi

mysql - 我如何在 MySQL 中获取季度的第一个日期?

转载 作者:可可西里 更新时间:2023-11-01 06:35:02 24 4
gpt4 key购买 nike

到目前为止,我的代码如下:我试图找出用什么代替我的 ?,以找到该日期所在季度的开始日期。

SELECT
QUARTER(r.callDate) AS quar,
YEAR(r.callDate) AS ryear,
???????? AS scoreDateStart,
(SELECT DATE (DATE_SUB( DATE_ADD( CONCAT( YEAR( r.callDate ), '-01-01'), INTERVAL QUARTER(r.callDate) QUARTER ), INTERVAL 1 DAY))) AS scoreDateEnd,
group_concat(DISTINCT(r.resultId) separator ', ') AS resultIds
FROM results AS r
GROUP BY quar, ryear
ORDER BY quar;

我试过谷歌搜索但无济于事。

输出示例如下:

'1', '2012', '2012-01-01', '2012-03-31', '57, 58, 59'
'2', '2012', '2012-04-01', '2012-06-30', '10549, 10551, 12598'

最佳答案

试试这个:

要获取当前季度的开始日期,请使用:

  SELECT  MAKEDATE(YEAR(CURDATE()), 1) + INTERVAL QUARTER(CURDATE()) QUARTER 
- INTERVAL 1 QUARTER

所以您的查询将是:

SELECT
QUARTER(r.callDate) AS quar,
YEAR(r.callDate) AS ryear,
MAKEDATE(YEAR(r.callDate), 1) + INTERVAL QUARTER(r.callDate) QUARTER -
INTERVAL 1 QUARTER AS scoreDateStart,
(SELECT DATE (DATE_SUB( DATE_ADD( CONCAT( YEAR( r.callDate ), '-01-01'),
INTERVAL QUARTER(r.callDate) QUARTER ), INTERVAL 1 DAY))) AS scoreDateEnd,
group_concat(DISTINCT(r.resultId) separator ', ') AS resultIds
FROM results AS r
GROUP BY quar, ryear
ORDER BY quar;

关于mysql - 我如何在 MySQL 中获取季度的第一个日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11884618/

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