I have an SQL database (pq) with 3 tables as sample is shown in image. I am trying to achieve below things:
Select only rows with variable
P
from theMEASUREMENT column
inTable 3
. I tried below query but it didnt produced the correct output.select distinct pq_data.READ_TIME,OBS_METER,MEASUREMENT,VALUE from pq_data ORDER BY MEASUREMENT;
Then, fetch the data columns
CUST_CLASS
, andSOLAR
from Table 1 into Table 3 according toOBS_METER
id. TheOBS_METER
column is not available in Table 1 but the it can be obtained fromOBS_LOCATION
in Table 2.The expected output of SQL query is Table 3 with additional columns from other tables,such as:
row id READ_TIME OBS_METER OBS_LOCATION MEASUREMENT VALUE CUST_CLASS SOLAR
28/01/2018 2018/01/28 01:55:00 105714 6787 P 284 R F
..........
I searched for existing answers: 1 , 2 but I couldnt able to write a SQL query which will produce above expected output.