15,169,085 members
See more:
Hi,
I have a table as below.

SQL
```Id  FromPlace ToPlace TotalSend      Date             TotalPrice

1     A       B         3           1/Mar/2015               2000
2     A       C         4           1/Mar/2015               3000
3     B       A         3           3/Mar/2015               1000
4     B       C         6           3/Mar/2015               1500
5     A       B         2           3/Mar/2015                600
6     C       B         6           8/Mar/2015               3000
7     C       A         2           10/Mar/2015              500
8     B       A         1           11/Mar/2015              600
9     B       C         2           14/Mar/2014              700           ```

Output Needed as below
SQL
```Place TotalSendTo TotalSendFrom  TotToFrom  TotPriceTo TotPriceFrom TotalPriceFrom

A         9           6              15         5600       1100           6700
B         12          11             23         3800       5600           9400
C         8           12             20         3500       5200           8700  ```

I need to sum Totalsend and TotalPrice as per Place (A,B,C)
Posted

## Solution 1

Try:
SQL
```SELECT f.FromPlace AS Place,
f.TotalSendFrom,
t.TotalSendTo,
f.TotalSendFrom + t.TotalSendTo AS TotToFrom,
f.TotPriceFrom,
t.TotPriceTo,
t.TotPriceTo + f.TotPriceFrom As TotalPrice
FROM (SELECT FromPlace, SUM(TotalSend) AS TotalSendFrom, SUM(TotalPrice) AS TotPriceFrom
FROM MyTable GROUP BY FromPlace) f
JOIN (SELECT ToPlace, SUM(TotalSend) AS TotalSendTo, SUM(TotalPrice) AS TotPriceTo
FROM MyTable GROUP BY ToPlace) t
ON t.ToPlace = f.FromPlace```