database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
ㆍOracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
Oracle Q&A 38628 게시물 읽기
No. 38628
고수님들 쿼리질문입니다.
작성자
쫑~~(testfive)
작성일
2011-06-22 12:46ⓒ
2011-06-22 13:03ⓜ
조회수
4,353

COL_A    COL_B         COL_C

001          20110513  30

001         20110512    20

001         20110511    40

.

.

002         20110513    50

002        20110512     70

002         20110511   40

.

.

.

데이타가 이런식으로 들어가 있어요

데이타 건수는 날짜별로 한 2백만건 정도 되구요

 

결과값은  기준은 COL_A별로

 

001 평균값(001 로우5개합한값)  평균값(001 로우10개합한값)  평균값(001 로우15개합한값) 

002 평균값(002 로우5개합한값)  평균값(002 로우10개합한값)  평균값(002 로우15개합한값) 

 

을 구하고 싶어요

평균값은 ROW 5개를 합한값, 10개를 합한값 15개를 합한값의 평균을 구해야 하는데

잘안되네요 여러고수님들 쿼리 좀 도와주세요^^

이 글에 대한 댓글이 총 1건 있습니다.

with t as (
select '001' col_a, '20110512' col_b, 10  col_c from dual union all
select '001', '20110511', 20 from dual union all
select '001', '20110512', 30 from dual union all
select '001', '20110511', 40 from dual union all
select '001', '20110512', 50 from dual union all
select '001', '20110511', 60 from dual union all
select '001', '20110512', 70 from dual union all
select '001', '20110511', 80 from dual union all
select '001', '20110512', 90 from dual union all
select '001', '20110511', 100 from dual union all
select '001', '20110512', 110 from dual union all
select '001', '20110511', 120 from dual union all
select '001', '20110512', 130 from dual union all
select '001', '20110511', 140 from dual union all
select '001', '20110513', 150 from dual union all
select '002', '20110513', 160 from dual union all
select '002', '20110512', 170 from dual union all
select '002', '20110511', 180 from dual union all
select '002', '20110513', 190 from dual union all
select '002', '20110512', 200 from dual union all
select '002', '20110511', 210 from dual union all
select '002', '20110513', 220 from dual union all
select '002', '20110512', 230 from dual union all
select '002', '20110511', 240 from dual union all
select '002', '20110513', 250 from dual union all
select '002', '20110512', 260 from dual union all
select '002', '20110511', 270 from dual union all
select '002', '20110513', 280 from dual union all
select '002', '20110512', 290 from dual union all
select '002', '20110511', 300 from dual
)
select col_a
     , count(case when rn5 <= 1 then col_c end) cnt_5
     , sum  (case when rn5 <= 1 then col_c end) sum_5
     , avg  (case when rn5 <= 1 then col_c end) avg_5
     , count(case when rn5 <= 2 then col_c end) cnt_10
     , sum  (case when rn5 <= 2 then col_c end) sum_10
     , avg  (case when rn5 <= 2 then col_c end) avg_10
     , count(case when rn5 <= 3 then col_c end) cnt_15
     , sum  (case when rn5 <= 3 then col_c end) sum_15
     , avg  (case when rn5 <= 3 then col_c end) avg_15
  from (
         select col_a
              , col_b
              , col_c
              , row_number()over(partition by col_a order by 1) rn
              , ceil(row_number()over(partition by col_a order by 1) / 5) rn5
           from t
     )
 group by col_a

知音(sunnylee72)님이 2011-06-22 13:43에 작성한 댓글입니다.
이 댓글은 2011-06-22 13:45에 마지막으로 수정되었습니다.
[Top]
No.
제목
작성자
작성일
조회
38631고수님들 도와주세요~!! [1]
조현욱
2011-06-23
3617
38630간단한것 같은데 잘 모르겠네요 도움좀 부탁드립니다. [4]
나그네
2011-06-22
4370
38629쿼리 튜닝 부탁드립니다. 아님 방도라도..ㅠㅠ
무심도
2011-06-22
5120
38628고수님들 쿼리질문입니다. [1]
쫑~~
2011-06-22
4353
38627[오라클] 전체 백업 후 복구실패 [1]
zark
2011-06-22
4363
38626char 조회조건 잘 되지 않습니다. [3]
열심히
2011-06-21
3580
38625이상해요 [1]
초짜
2011-06-21
3019
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.019초, 이곳 서비스는
	PostgreSQL v16.4로 자료를 관리합니다