: count 보다는 sum 을 이용하는게 좋다.
SELECT
CONVERT(varchar(10),regDate,112) AS regDate,
COUNT(*) total,
COUNT(CASE maxOrderText WHEN 1 THEN maxOrderText ELSE null END) men,
COUNT(CASE maxOrderText WHEN 0 THEN maxOrderText ELSE null END) women,
sum(CASE WHEN maxOrder < 10 THEN 1 ELSE 0 END) age00,
sum(CASE WHEN maxOrder between 10 and 20 THEN 1 ELSE 0 END) age10,
sum(CASE WHEN maxOrder between 20 and 30 THEN 1 ELSE 0 END) age20,
sum(CASE WHEN maxOrder between 30 and 40 THEN 1 ELSE 0 END) age30,
sum(CASE WHEN maxOrder > 40 THEN 1 ELSE 0 END) age40
/*
(SELECT COUNT(*) FROM tblshopgoods WHERE maxOrder < 10 ) as age00,
(SELECT COUNT(*) FROM tblshopgoods WHERE maxOrder between 10 and 20) as age10,
(SELECT COUNT(*) FROM tblshopgoods WHERE maxOrder between 20 and 30) as age20,
(SELECT COUNT(*) FROM tblshopgoods WHERE maxOrder between 30 and 40) as age30,
(SELECT COUNT(*) FROM tblshopgoods WHERE maxOrder > 40) as age40
*/
FROM dbo.tblShopGoods
GROUP BY CONVERT(varchar(10),regDate,112)
Posted by 홍반장