SELECT
COUNT(CASE WHEN DATEDIFF(CURRENT_DATE, updated_at) < 1 THEN 1 END) AS diff_lt_1,
COUNT(CASE WHEN DATEDIFF(CURRENT_DATE, updated_at) >= 1 AND
DATEDIFF(CURRENT_DATE, updated_at) < 3 THEN 1 END) AS diff_1_to_3,
COUNT(CASE WHEN DATEDIFF(CURRENT_DATE, updated_at) >= 3 AND
DATEDIFF(CURRENT_DATE, updated_at) < 7 THEN 1 END) AS diff_3_to_7,
COUNT(CASE WHEN DATEDIFF(CURRENT_DATE, updated_at) >= 7 THEN 1 END) AS diff_gt_7
FROM Table;
实际上还不清楚你应该在哪一列做文章 GROUP BY . 我们可以修改上面的查询,如果您显示的样本数据显示您正在尝试做什么。
1条答案
按热度按时间jv4diomz1#
使用条件聚合:
实际上还不清楚你应该在哪一列做文章
GROUP BY
. 我们可以修改上面的查询,如果您显示的样本数据显示您正在尝试做什么。