현재 테이블에
2014-08-28 00:00:00.000
2014-08-28 00:10:00.000
2014-08-28 00:20:00.000
이런식으로 시간필드에 10분단위로 로우가 쌓여있습니다.
이외의 필드에 각종 데이터들이 있구요
이걸 시간단위로 grouping 되어져있는 프로시져가 있는데 문제는
한개의 필드만 50분~50분 단위로 sum을 해서 리스트를 뿌려달라고합니다.
SELECT
DATEPART(Hh,InsertDateTime) AS InsertDateTime,
sum(JYW) as JYW,
sum(JYH) as JYH
FROM
Table A WITH (NOLOCK)
GROUP BY
DATEPART(Hh,A.InsertDateTime)
간략하게 말씀드리면 위의 쿼리에서 jyh값만 시간단위 그루핑이 아니라 예를 들면 1시 50분 부터 2시 50분까지 데이터를 sum해서 뿌려달라는 말인데.. 생각이 잘 안납니다 ㄷㄷ
어떻게 해야될지 팁좀 알려주시면 감사하겠습니다
Comment 4
-
짱나부러
2015.09.10 17:19
with test (iDate, val) as(select '2015-09-10 00:10:00', 1 union allselect '2015-09-10 00:20:00', 1 union allselect '2015-09-10 00:30:00', 1 union allselect '2015-09-10 00:40:00', 1 union allselect '2015-09-10 00:50:00', 1 union allselect '2015-09-10 01:00:00', 1 union allselect '2015-09-10 01:10:00', 1 union allselect '2015-09-10 01:20:00', 1 union allselect '2015-09-10 01:30:00', 1 union allselect '2015-09-10 01:40:00', 1 union allselect '2015-09-10 01:50:00', 1 union allselect '2015-09-10 02:00:00', 1 union allselect '2015-09-10 02:10:00', 1 union allselect '2015-09-10 02:20:00', 1 union allselect '2015-09-10 02:30:00', 1 union allselect '2015-09-10 02:40:00', 1 union allselect '2015-09-10 02:50:00', 1 union allselect '2015-09-10 03:00:00', 1 union allselect '2015-09-10 03:10:00', 1 union allselect '2015-09-10 03:20:00', 1 union allselect '2015-09-10 03:30:00', 1 union allselect '2015-09-10 03:40:00', 1 union allselect '2015-09-10 03:50:00', 1 union allselect '2015-09-10 04:00:00', 1)select sum(val) as val1,sum(case when iDate between '2015-09-10 01:50:00' and '2015-09-10 02:50:00' then val else 0 end) as val2from test이렇게 풀수도 있지 않을까요....? -
새우볶음
2015.09.11 10:45
아무래도 힘들듯 싶어요 ㅜㅜ
-
새우볶음
2015.09.11 10:44
도저히 방법이 안되서 금기인 function을 사용해서 해결했네요 ㅜㅜ
뭐 많은 결과물을 출력하는게 아니라 속도차이가 없어서 다행이네요
-
건우아빠
2015.09.17 10:36
왜 function을 쓰면 금기죠 ?