日期:2014-05-16 浏览次数:20881 次
------莫非lz抖了3下,菜鸟来接分哈。。。呵呵 SQL> SQL> with tablea as 2 ( 3 select '1234567890' msn,1 j_value, 1 j_type, date '2010-12-27' j_date from dual union all 4 select '1234567890' msn,2 j_value, 2 j_type, date '2010-12-27' j_date from dual union all 5 select '1234567890' msn,1 j_value, 3 j_type, date '2010-12-27' j_date from dual union all 6 select '1234567890' msn,3 j_value, 4 j_type, date '2010-12-27' j_date from dual union all 7 select '1234567890' msn,5 j_value, 5 j_type, date '2010-12-27' j_date from dual union all 8 select '1234567890' msn,1 j_value, 3 j_type, date '2010-12-23' j_date from dual union all 9 select '1234567890' msn,3 j_value, 4 j_type, date '2010-12-23' j_date from dual union all 10 select '1234567890' msn,5 j_value, 5 j_type, date '2010-12-23' j_date from dual 11 ) 12 select msn 用户手机号码, 13 max(decode(j_type, 1, j_value)) 积分值一, 14 max(decode(j_type, 2, j_value)) 积分值二, 15 max(decode(j_type, 3, j_value)) 积分值三, 16 max(decode(j_type, 4, j_value)) 积分值四, 17 max(decode(j_type, 5, j_value)) 积分值五, 18 dvalue 当天累计积分值, 19 mvalue 当月总积分值, 20 tvalue 总积分值 21 from (select msn, 22 j_value, 23 j_type, 24 j_date, 25 sum(j_value) over(partition by trunc(j_date) order by 1) dvalue, 26 sum(j_value) over(partition by trunc(j_date, 'mm') order by 1) mvalue, 27 sum(j_value) over(order by 1) tvalue 28 from tablea) 29 group by msn, dvalue, mvalue, tvalue 30 ; 用户手机号码 积分值一 积分值二 积分值三 积分值四 积分值五 当天累计积分值 当月总积分值 总积分值 ------------ ---------- ---------- ---------- ---------- ---------- -------------- ------------ ---------- 1234567890 1 3 5 9 21 21 1234567890 1 2 1 3 5 12 21 21 SQL>