我的问题是:
SELECT
(CASE
WHEN service_year <= 2 THEN '0-2'
WHEN service_year BETWEEN 3 AND 5 THEN '3-5'
WHEN service_year BETWEEN 6 AND 9 THEN '6-9'
WHEN service_year > 9 THEN '>9'
WHEN service_year IS NULL THEN '(NULL)'
END) AS range_service,
COUNT(*) as jumlah
FROM (SELECT gender, TIMESTAMPDIFF(YEAR, join_date, CURDATE()) AS service_year FROM employee) AS dummy_table
GROUP BY range_service
ORDER BY range_service
输出为:
我要这样做:
1条答案
按热度按时间snvhrwxg1#
你可以用if和case当