SELECT id, login_id, count, case when count = 0 then 'Cat_A' WHEN count between 1 and 10 then 'Cat_B' WHEN count > 10 then 'Cat_C' WHEN count IS NULL THEN 'Cat D' END as Category FROM ( select id,login_id,min(ord_count) AS count FROM table_1 X JOIN table_2 Y ON X.id_col = Y.id_col WHERE date = '2022-02-02' AND login_id = 'True' group by id,login_id )A LEFT JOIN ( SELECT id,COUNT(X.ord_no) AS count_of_orders FROM table_1 X WHERE X.date = '2022-02-02' group by id )B ON A.id=B.id When I join these two tables, I'm getting NULL values for the unmatched records. I need to replace those NULL records to some hardcoded value say 'XYZ'.
Any guidance on how to achieve this please?
NVL( COLUMN_TO_CHECK , 'XYZ' )unless there's more that needs to happen here.idis present in bothaandbaliased derived tables. As far as I can tell you are only using columns from aliasa, so why even join? At any rate, it's not clear what you mean "NULL values for the unmatched records". It's hard to talk about data and records when all we can are given is broken sql. Please share sample data and desired results.