针对一行中的ID显示多行 - Oracle SQL

时间:2018-04-02 13:21:31

标签: oracle pivot transpose

我的问题与以下内容有关: Display multiple values of a column in one row (SQL Oracle)

但是,我无法达到预期的效果。以下是我的问题陈述;

我有一个SQL查询;

SELECT initiator_msisdn,  trx_type  || '/'  || SUM(trx_amt/100)  || '/'  || SUM(merchant_comm_amt/100) agent_data
FROM LBI_DM_MK.T_M_INTERNAL_AUDIT_D
WHERE DATA_DATE = '20180401'
AND trx_status  ='Completed'
GROUP BY initiator_msisdn,  trx_type
;

返回这些行;

enter image description here

带来这些数据的SQL是;

但是,我想要以下结果。

enter image description here

请帮助解决此问题;

1 个答案:

答案 0 :(得分:1)

您可以使用WITH cte AS ( SELECT initiator_msisdn, trx_type || '/' || SUM(trx_amt/100) || '/' || SUM(merchant_comm_amt/100) agent_data FROM LBI_DM_MK.T_M_INTERNAL_AUDIT_D WHERE DATA_DATE = '20180401' AND trx_status ='Completed' GROUP BY initiator_msisdn, trx_type ) SELECT initiator_msisdn, LISTAGG(agent_data, '|') WITHIN GROUP (ORDER BY agent_data) AS agent_data FROM cte GROUP BY initiator_msisdn;

java.lang.ClassFormatError: Truncated class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at com.sun.jnlp.JNLPClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at <...>.ApplicationImpl.<init>(ApplicationImpl.java:63)