Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Better ways to write below query

Vineetha Tauro-OracleSep 4 2024 — edited Sep 4 2024

WITH temp_table1
AS (
SELECT
DISTINCT client,
c_type,
0 AS IND
FROM
table1
UNION
SELECT
DISTINCT client,
c_type,
0 AS IND
FROM
table2
),
temp_all_types
AS (
SELECT
DISTINCT client,
( CASE
WHEN Upper(c_type) = 'NON-UC' THEN ind + 0
WHEN Upper(c_type) IN ( 'UC', 'UCMS', 'UCRB' )
THEN
ind + 1
END ) AS IND
FROM
temp_table1)
SELECT
client,
( CASE
WHEN ind = 0 THEN 'NON-UC'
ELSE 'UC'
END ) AS c_type
FROM
(
SELECT
client,
Sum(ind) AS IND
FROM
temp_all_types t
GROUP BY
client)R;

Comments
Post Details
Added on Sep 4 2024
5 comments
158 views