i want to display new column in select query which will contain the sum of values from other table with corresponding to the id. I am learning Sql now so just want to know how to do it my problem is further explained as.


i want to display new column in select query which will contain the sum of values from other table with corresponding to the id. I am learning Sql now so just want to know how to do it my problem is further explained as.


SELECT table2.t1_id,table1.name,
sum(case when month='Jan' then amount else 0 end) as jan,
sum(case when month='feb' then amount else 0 end) as feb,
sum(case when month='Mar' then amount else 0 end) as Mar
from table2 inner
join table1 on table1.t1_id=table2.t1_id group by table2.t1_id,name
order by table2.t1_id;