Hi @ASHMITP
First of all, there are a few things in your code that confuse me.
In Q1. If you want to query C1 in table1, C2 in table2, and C3 in table3, the query statement should look like this.
Select Table1.C1,Table2.C2,Table3.C3 FROM Table1,Table2,Table3;
In Q2. I guess you want to group by Table4.C1, Table4.C2.
How to merge this two view in one common fiels is Table1.C1 (Q1) and Table4.C1 (Q2)
Since the two queries have a common field, I guess it should be using a table join. But I'm not sure which connection you need, inner join or left outer join or something else. I'll use inner joins as a demonstration.
;with T1 as(
Select Table1.C1,Table2.C2,Table3.C3 FROM Table1,Table2,Table3
),T2 as(
Select Table4.C1,Table4.C2,Sum(C3) as sumc3,Sum(C4) as sumc4 FROM Table4 Group By Table4.C1, Table4.C2)
select * from T1 as A inner join T2 as B on A.C1 = B.C1;
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.