Hi,
At present I have a logic implemented like below code example where I can get a combination of columns cid and ani in 'config' table to which I have to map columns cid and ani present in my 'current' table.
Now, a new column pid is added to both 'config' and 'current' tables, like
alter table config add pid integer
alter table current add pid integer
Now I can have data in a combination of cid and ani (where pid can be NULL) or cid and pid (where ani can be NULL) or a row where all cid, ani and pid can have values. In this scenario, how should I make the changes in the current implementation given below?
Regards.
create table current (cid integer, ani integer, resetdate datetime, threshold integer) create table config (cid integer, ani integer, resetdate datetime, threshold integer ) SELECT cid, ani from ( SELECT A.cid, A.ani, CASE WHEN C.cid is null then B.resetdate ELSE C.resetdate END AS resetdate, CASE WHEN C.cid is null then B.threshold ELSE C.threshold END AS threshold FROM current AS A LEFT JOIN ( SELECT cid, ani ,resetdate , threshold from config ) AS B ON A.cid = B.cid AND B.ani is null LEFT JOIN ( SELECT cid, ani ,resetdate , threshold from config ) AS C ON A.cid = C.cid AND A.ani = C.ani WHERE A.ani IS NOT NULL )AS D GROUP BY cid, ani