-1

I have a DATA Table :

                COLUMN:  City    Deposittype  DepositAmount                  
                ROWS :  city1     new          100
                        city1     new          200
                        city2     old          200
                        city2     old          100
                        city2     new          200
                         city3    new          100

Want to Group by city, calc sum of depositamount for specified Deposittype.

Example, for condition depositType= new

i want a row like

               city1 city2 city3
                300   200   100

I want sum of DepositAmounts Grouped by City with specific Deposit type. i.e Result row should have city1 city2 city3 as column names, under which sum of 'Depositamounts' for a specified loan type say Deposittype = new.

2 Answers2

0
SELECT City, SUM(DepositAmount) FROM myTable
WHERE Deposittype = 'new'
GROUP BY City
Petar Ivanov
  • 91,536
  • 11
  • 82
  • 95
0
SELECT  
   (
    SELECT SUM(DepositAmount) FROM myTable 
    WHERE Deposittype = 'New' AND City = 'City1'
   ) AS City1,
   (
    SELECT SUM(DepositAmount) FROM myTable 
    WHERE Deposittype = 'New' AND City = 'City2'
   ) AS City2,
   (
    SELECT SUM(DepositAmount) FROM myTable 
    WHERE Deposittype = 'New' AND City = 'City3'
   ) AS City3

FROM    myTable
Yaqub Ahmad
  • 27,569
  • 23
  • 102
  • 149