I have two tables,
Table_1 contains like,
Project_name Date value
P1 15/06/2016
P2 25/04/2017
P3 18/06/2017
P4 12/05/2017
Table_2 contains like,
Name Occ_June_2016 Occ_April_2017 Occ_May_2017 Occ_June_2017
P1 8.1 7.5 6.5 8.2
P2 8.3 7.4 6.0 8.5
P3 8.6 7.1 6.1 8.1
P4 8.8 7.9 6.8 8.9
I want to get the value, based on mapping the project_name and the date.
Here is what i have tried. Converting table_1 date column to a particular format,
SELECT to_char(to_date(a.date, 'DD-MM-YYYY'), 'mon_YYYY') from table_1 a ;
Output I got as,
jun_2016
apr_2017
jun_2017
may_2017
By using output above i want to search the column in table_2 by matching the column and name,
Am trying to get the columns based on partial match condition,
select column_name from information_schema.COLUMNS as c where c.TABLE_NAME = 'table_2' and c.COLUMN_NAME like '%occ_%';
Here is the output for the above query,
Occ_June_2016
Occ_April_2017
Occ_May_2017
Occ_June_2017
Now i need to take the output of one query to the input of one query Here is where am stucked. Mapping the date based on name.
My output should be like,
Project_name Date value
P1 15/06/2016 8.1
P2 25/04/2017 7.4
P3 18/06/2017 8.1
P4 12/05/2017 6.8
kindly give me a solution. Thanks in advance