我的表格包含以下列 -
我需要根据从创建日期开始的日期和日期范围来计算事件。
例如
Date Range || Open || Closed ||
1-2 days || 5 || 6 ||
2-5 days || 4 || 8 ||
5-15 days || 10 || 15 ||
任何帮助都将不胜感激,谢谢。
答案 0 :(得分:1)
SELECT CASE WHEN DATEDIFF(created_date, now()) BETWEEN 1 AND 2
THEN '1-2 days'
WHEN DATEDIFF(created_date, now()) BETWEEN 3 AND 5
THEN '3-5 days'
WHEN DATEDIFF(created_date, now()) BETWEEN 6 AND 15
THEN '6-15 days'
ELSE '> 15 days'
END AS DateRange,
SUM(CASE WHEN Status = 'open' THEN 1 ELSE 0 END) AS Open,
SUM(CASE WHEN Status = 'closed' THEN 1 ELSE 0 END) AS Closed
FROM YourTable
GROUP BY DateRange