I have a table with data as below
DB DBMS INST SCHEMA TABLE COLUMN HDFT N_Identity Class
IDS TD SBD IDS Data_Val cust_t HIGH
IDS TD SBD IDS Data_Val cust_t GID
IDS TD SBD IDS Data_Val cust_t Phone
IDS TD SBD IDS Data_Val cust_t Account
IDS TD SBD IDS Data_Val cust_t Visa
IDS TD SBD IDS Data_Val cust_t Mail
IDS TD SBD IDS Data_Val cust_t Email
IDS TD SBD IDS Data_Val cust_t Login Yes
TDS TD FDT TDS Expense Exp_t Name LOW
TDS TD FDT TDS Expense Exp_t Yes
I want the output as below:
DB DBMS INST SCHEMA TABLE COLUMN HDFT N_Identity Class
IDS TD SBD IDS Data_Val cust_t GID Yes HIGH
IDS TD SBD IDS Data_Val cust_t Phone Yes HIGH
IDS TD SBD IDS Data_Val cust_t Account Yes HIGH
IDS TD SBD IDS Data_Val cust_t Visa Yes HIGH
IDS TD SBD IDS Data_Val cust_t Mail Yes HIGH
IDS TD SBD IDS Data_Val cust_t Email Yes HIGH
IDS TD SBD IDS Data_Val cust_t Login Yes HIGH
TDS TD FDT TDS Expense Exp_t Name Yes LOW
N_identity will have either Yes or No value for a particular column.So far i have tried to use the below query but it's not giving me the desired result:
SELECT * FROM
(
SELECT * FROM
(
SELECT DB,DBMS,INST,SCHEMA,TABLE,COLUMN, MAX(HDFT) as HDFT, MAX(N_Identity) as N_Identity, MAX(Class) as Class
FROM Table
GROUP BY DB,DBMS,INST,SCHEMA,TABLE,COLUMN
)a
UNION
SELECT DB,DBMS,INST,SCHEMA,TABLE,COLUMN, HDFT, N_Identity, Class FROM Table
)b
WHERE HDFT IS NOT NULL
AND N_Identity IS NOT NULL
AND Class IS NOT NULL
Updated requirement: The HDFT value can be null and below is one scenario:
DB DBMS INST SCHEMA TABLE COLUMN HDFT N_Identity Class
IDS TD SBD IDS Data_Val cust_t No INT
IDS TD SBD IDS Data_Val cust_t INT
IDS TD SBD IDS Data_Val cust_t No
Result Expected:
DB DBMS INST SCHEMA TABLE COLUMN HDFT N_Identity Class
IDS TD SBD IDS Data_Val cust_t No INT