Try replacing
GROUP BY CUBE(status, CASE WHEN status IN(2, 4, 5) THEN 1 ELSE 0 END)
with
GROUP BY CUBE(TRANSACTION_STATUS_CODES.DESCRIPTION, CASE WHEN TRANSACTIONS.status IN(2, 4, 5) THEN 1 ELSE 0 END)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
hello.
I have the following query:
SELECT CASE GROUPING_ID(status, CASE WHEN status IN(2, 4, 5) THEN 1 ELSE 0 END)
WHEN 0 THEN TO_CHAR(status)
WHEN 2 THEN 'sum statuses 2,4,5'
ELSE 'sum'
END AS status,
case
when status = 0 then 'page was closed'
when status = 2 then 'isnt card owner'
when status = 3 then 'error'
when status = 4 then 'charge'
when status = 5 then 'got report, charge failed'
end as "description" ,
COUNT(CASE user_type WHEN 1 THEN 1 END) AS "1",
COUNT(CASE user_type WHEN 2 THEN 1 END) AS "2",
COUNT(CASE user_type WHEN 3 THEN 1 END) AS "3",
COUNT(CASE user_type WHEN 5 THEN 1 END) AS "5",
COUNT(*) AS total
FROM TRANSACTIONS WHERE status != 1 AND Update_Date BETWEEN TO_DATE('2022-01-04', 'yyyy-mm-dd HH24:MI:SS') AND TO_DATE('2022-12-07', 'yyyy-mm-dd HH24:MI:SS')
GROUP BY CUBE(status, CASE WHEN status IN(2, 4, 5) THEN 1 ELSE 0 END)
HAVING GROUPING_ID(status, CASE WHEN status IN (2, 4, 5) THEN 1 ELSE 0 END) IN(0, 3)
OR(GROUPING_ID(status, CASE WHEN status IN(2, 4, 5) THEN 1 ELSE 0 END) = 2 AND CASE WHEN status IN(2, 4, 5) THEN 1 ELSE 0 END = 1)
which displays:
I want to remove that part from code:
case
when status = 0 then 'page was closed'
when status = 2 then 'isnt card owner'
when status = 3 then 'error'
when status = 4 then 'charge'
when status = 5 then 'got report, charge failed'
end as "description" ,
Originally the "DESCRIPTION" column is found in a different table called TRANSACTION_STATUS_CODES.
I want to change my FROM statement: FROM TRANSACTIONS to FROM TRANSACTIONS, TRANSACTION_STATUS_CODES and then to select the TRANSACTION_STATUS_CODES.DESCRIPTION
so far so good. when doing so (because Im using aggregate functions in my select statement, I cannot randomally add a column to the result set without having to include it in the GROUPBY clause. which makes it hard for me to catch up on how to do that...
Maybe this is a partition by's job?
but Im not sure and have no clue how to implement this in my query, any suggestions?
thanks !
Try replacing
GROUP BY CUBE(status, CASE WHEN status IN(2, 4, 5) THEN 1 ELSE 0 END)
with
GROUP BY CUBE(TRANSACTION_STATUS_CODES.DESCRIPTION, CASE WHEN TRANSACTIONS.status IN(2, 4, 5) THEN 1 ELSE 0 END)