oracle按半小时统计,Oracle按年如何进行统计?

按照年统计

view plaincopy to clipboardPRint?

WITH tmp_table AS (SELECT MAX(TO_CHAR(T。PURRECEIVEDATE, ’yyyy’)) -

MIN(TO_CHAR(T。

PURRECEIVEDATE, ’yyyy’)) AS NUM,

MIN(TO_CHAR(T。PURRECEIVEDATE, ’yyyy’)) AS MINYEAR

FROM LB01_PURRECEIVEBOOK T

),

select_table AS (

SELECT TMP。

YEARSUM, TMP。YEAR, TMP。YMD

FROM (SELECT SUM(T。RECEIVEAMT) OVER(PARTITION BY TO_CHAR(T。PURRECEIVEDATE, ’yyyy’) ORDER BY T。

PURRECEIVEDATE DESC) AS YEARSUM,

TO_CHAR(T。PURRECEIVEDATE, ’yyyy’) AS YEAR,

TO_CHAR(T。PURRECEIVEDATE, ’yyyy/mm/dd’) AS YMD,

ROW_NUMBER() OVER(PARTITION BY TO_CHAR(T。

PURRECEIVEDATE, ’yyyy’) ORDER BY T。PURRECEIVEDATE) AS RN

FROM LB01_PURRECEIVEBOOK T) TMP

WHERE TMP。RN = 1

),

creatyear_table AS (

SELECT tmp_table。

MINYEAR + LEVEL - 1 AS tmp_year FROM DUAL, tmp_table

CONNECT BY LEVEL <= tmp_table。NUM + 1

)

SELECT

ct。tmp_year,

NVL(st。

YEARSUM, 0) AS YEARSUM

FROM

creatyear_table ct,

select_table st

WHERE

ct。tmp_year = st。year(+)

WITH tmp_table AS (SELECT MAX(TO_CHAR(T。

PURRECEIVEDATE, ’yyyy’)) -

MIN(TO_CHAR(T。PURRECEIVEDATE, ’yyyy’)) AS NUM,

MIN(TO_CHAR(T。PURRECEIVEDATE, ’yyyy’)) AS MINYEAR

FROM LB01_PURRECEIVEBOOK T

),

select_table AS (

SELECT TMP。

YEARSUM, TMP。YEAR, TMP。YMD

FROM (SELECT SUM(T。RECEIVEAMT) OVER(PARTITION BY TO_CHAR(T。PURRECEIVEDATE, ’yyyy’) ORDER BY T。

PURRECEIVEDATE DESC) AS YEARSUM,

TO_CHAR(T。PURRECEIVEDATE, ’yyyy’) AS YEAR,

TO_CHAR(T。PURRECEIVEDATE, ’yyyy/mm/dd’) AS YMD,

ROW_NUMBER() OVER(PARTITION BY TO_CHAR(T。

PURRECEIVEDATE, ’yyyy’) ORDER BY T。PURRECEIVEDATE) AS RN

FROM LB01_PURRECEIVEBOOK T) TMP

WHERE TMP。RN = 1

),

creatyear_table AS (

SELECT tmp_table。

MINYEAR + LEVEL - 1 AS tmp_year FROM DUAL, tmp_table

CONNECT BY LEVEL <= tmp_table。NUM + 1

)

SELECT

ct。tmp_year,

NVL(st。

YEARSUM, 0) AS YEARSUM

FROM

creatyear_table ct,

select_table st

WHERE

ct。tmp_year = st。year(+)。

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值