I am not sure where to put the case statement whether in select or where clause. I am trying to get data from table c when cnt_subj = MEPC_PL then metric_id will be equal to 6135 from table m. Can anyone help? Thank you in advance! ๐
โx
SELECT DISTINCT
m.metric_id AS metric_id,
m.subject_abbrevn AS p_subj,
m.table_abbrevn AS cnt_subj,
c.p_id AS p_id,
c.cnt_id AS cnt_id,
c.gl_id AS gl_id,
case c.cnt_subj
when 'MEPC_PL' then 6135
end m.metric_id
FROM
T_CROMS_CAT_T m,
croms_qc_currency_1_v c
โ
Advertisement
Answer
I think this is the query you are looking for:
SELECT DISTINCT
m.metric_id AS metric_id,
m.subject_abbrevn AS p_subj,
m.table_abbrevn AS cnt_subj,
c.p_id AS p_id,
c.cnt_id AS cnt_id,
c.gl_id AS gl_id,
FROM croms_qc_currency_1_v c
INNER JOIN T_CROMS_CAT_T m ON DECODE(c.cnt_subj, 'MEPC_PL', 6135, NULL) = m.metric_id;
โ
Do you actually need the DISTINCT
? Is there more than one row with those IDs?
Also, you can expand this if you have other CNT_SUBJ
values which you need to translate.