오라클 시간별 데이터 질문 드립니다 0 2 1,434

by 치비 [2016.04.22 14:17:18]


안녕하세요 

초보개발자 치비 입니다. 

과목,시간을 그룹으로 묶어서 나타내는 쿼리문인데

select to_char(reg_date,'MM-DD') 오늘날짜, 과목,
to_char(sum(decode(to_char(reg_date,'hh24'),'09',1,0))) 시간1,
to_char(sum(decode(to_char(reg_date,'hh24'),'10',1,0))) 시간2,
to_char(sum(decode(to_char(reg_date,'hh24'),'11',1,0))) 시간3,
to_char(sum(decode(to_char(reg_date,'hh24'),'12',1,0))) 시간4,
to_char(sum(decode(to_char(reg_date,'hh24'),'13',1,0))) 시간5,
to_char(sum(decode(to_char(reg_date,'hh24'),'14',1,0))) 시간6,
to_char(sum(decode(to_char(reg_date,'hh24'),'15',1,0))) 시간7,
to_char(sum(decode(to_char(reg_date,'hh24'),'16',1,0))) 시간8,
to_char(sum(decode(to_char(reg_date,'hh24'),'17',1,0))) 시간9,
to_char(sum(decode(to_char(reg_date,'hh24'),'18',1,0))) 시간10,
count(*) total from 테이블  group by to_char(reg_date,'MM-DD'),과목 order by 1;

여기서의 문제가 만약에 9시에서 10시 30분까지의 데이터를 구하기 위해서는 어떡해 해야할지 감이 안잡힙니다...

단순히 (reg_date,'hh24:mm'),'09:00',1,0) 이렇게 하면 (reg_date,'hh24:mm'),'10:30',1,0) 이러면 단순히 9시인 데이터와

10시 30분인 데이터만 가져오는 거라서 저가 원하는 데이터를 추줄할 수 가 없었습니다.

어떡해 하면 추출 할 수 있는지 조언을 부탁드립니다. 감사합니다^^

by 마농 [2016.04.22 14:48:23]
, COUNT(CASE WHEN TO_CHAR(reg_date, 'hh24:mi') BETWEEN '09:00' AND '10:29' THEN 1 END) 시간1
, COUNT(CASE WHEN TO_CHAR(reg_date, 'hh24:mi') BETWEEN '10:30' AND '11:59' THEN 1 END) 시간2

 


by 치비 [2016.04.22 15:39:27]

갓마농 사마 정말 감사합니다 ㅠ

와... 전 case when then 이렇게만 존재하는줄 알았는데... 그걸 between 으로 

해결 할 수 잇는지는 꿈에도 몰랐네요ㅠㅠ 다시한번 감사합니다 복받으세요!!

 

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입