-- 나이별 주문 내용 통계 구하기
: 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)
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2008/03/26 10:34 2008/03/26 10:34
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/3101

Trackback URL : http://tcbs17.cafe24.com/tc/trackback/3101

« Previous : 1 : ... 3322 : 3323 : 3324 : 3325 : 3326 : 3327 : 3328 : 3329 : 3330 : ... 6391 : Next »

블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2024/11   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Statistics Graph

Site Stats

Total hits:
240560
Today:
356
Yesterday:
856