我是Oracle Analytics的新手。任何人都可以帮我解决以下问题。Oracle分析函数用法
SELECT year,
month,
week,
C.cpg_pk CPG,
C.dep_pk DEPT,
T.cust_id CUST_ID,
D1.r_id R_ID,
Decode(d2.at_code, '3', func1.Get_att(d2.at_code, D2.val_code)) AS P1,
Decode(d2.at_code, '2', func1.Get_att(d2.at_code, D2.val_code)) AS IC,
Decode(d2.at_code, '1', func1.Get_att(d2.at_code, D2.val_code)) AS B1,
Decode(func1.Get_att(d2.at_code, D2.val_code), 2, d2.at_code) AS P2,
Decode(func1.Get_att(d2.at_code, D2.val_code), 5, d2.at_code) AS B2,
Count(DISTINCT A.cust_id) TOTAL_ACC
,
Count(DISTINCT T.txn_pk)
TOTAL_TXN,
SUM(am_amount) TOTAL_AMT
FROM t_header T,
cust_master A,
tx_details1 D1,
tx_details2 D2,
cpg_master C
WHERE A.TYPE = 0
AND T.cust_id = A.cust_id
AND T.txn_pk = 5001
AND T.txn_pk = D1.txn_pk
AND T.txn_pk = D2.txn_pk
AND D1.cpg_pk = C.cpg_pk
AND D1.op = 1
GROUP BY year,
month,
week,
C.cpg_pk,
C.dep_pk,
t.cust_id,
D1.r_id,
Decode(d2.at_code, '3', func1.Get_att(d2.at_code, D2.val_code)),
Decode(d2.at_code, '2', func1.Get_att(d2.at_code, D2.val_code)),
Decode(d2.at_code, '1', func1.Get_att(d2.at_code, D2.val_code)),
Decode(func1.Get_att(d2.at_code, D2.val_code), 2, d2.at_code),
Decode(func1.Get_att(d2.at_code, D2.val_code), 5, d2.at_code)
其产生的输出如下所示:
YEAR MONTH WEEK CPG DEPT CUST_ID R_ID P1 IC B1 P2 B2 TOTAL
2012 08 32 127 -1 10019 3665 134 23100.09
2012 08 32 127 -1 10019 3665 135 23100.09
2012 08 32 127 -1 10019 3665 723 23100.09
2012 08 32 127 -1 10019 3665 714 23100.09
2012 08 32 127 -1 10019 3665 41 23100.09
2012 08 32 127 -1 10019 3665 42 23100.09
2012 08 32 127 -1 10019 3665 21 23100.09
2012 08 32 128 -1 10019 3665 134 23100.09
2012 08 32 128 -1 10019 3665 135 23100.09
2012 08 32 128 -1 10019 3665 723 23100.09
2012 08 32 128 -1 10019 3665 714 23100.09
2012 08 32 128 -1 10019 3665 41 23100.09
2012 08 32 128 -1 10019 3665 42 23100.09
2012 08 32 128 -1 10019 3665 21 23100.09
这里的值被重复。我试图用group by
消除重复,但没有成功。你可以帮帮我吗?
所需的输出是这样的:
YEAR MONTH WEEK CPG DEPT CUST_ID R_ID P1 IC B1 P2 B2 TOTAL_AMT
---------------------------------------------------------------------------------
2012 08 32 127 -1 10019 3665 21 714 723 41 134 23100.09
2012 08 32 127 -1 10019 3665 21 714 723 41 135 23100.09
2012 08 32 127 -1 10019 3665 21 714 723 42 134 23100.09
2012 08 32 127 -1 10019 3665 21 714 723 42 135 23100.09
2012 08 32 128 -1 10019 3665 21 714 723 41 134 23100.09
2012 08 32 128 -1 10019 3665 21 714 723 41 135 23100.09
2012 08 32 128 -1 10019 3665 21 714 723 42 134 23100.09
2012 08 32 128 -1 10019 3665 21 714 723 42 135 23100.09
最主要的是year
,month
,week
,cpg
,dept
,cust_id
,r_id
,p1
,ic
,b1
,p2
,b2
它应该是唯一的行。使用分析函数可以实现,还是需要编写PL/SQL?我的问题很敏感吗?
可能的重复[我可以在这里使用Oracle分析函数吗?](http://stackoverflow.com/questions/12614209/can-i-use-oracle-analytical-function-here) –
是的,但输出不是给我期望的结果 – user1760970
因此,回答托尼的回答说为什么,并改进原来的问题 - 不要问一个相同的问题。请阅读[FAQ](http://stackoverflow.com/faq)。 –