1

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 have these two tables joined with t1_id

And result should produce the new column with month sum

Zebronix_777
  • 345
  • 4
  • 25

1 Answers1

0

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;

Zebronix_777
  • 345
  • 4
  • 25