MySQL区间统计SQL

SELECT
elt(
INTERVAL (
datediff(END_DATE, CURDATE()),
1,
201,
401,
601
),
'0-200',
'200-400',
'400-600',
'>600'
) AS `name`,
COUNT(INDIV_PIN) AS `value`
FROM
t_test
WHERE
    `STATUS` = 3
GROUP BY
elt(
INTERVAL (
datediff(END_DATE, CURDATE()),
1,
201,
401,
601
),
'0-200',
'200-400',
'400-600',
'>600'
),INDIV_PIN

posted @ 2018-04-03 10:41  关键我是你力哥  阅读(2494)  评论(0编辑  收藏  举报