sql grouping... thing
I have this data:
ID Country City Type Qty SomeDate SomeDate1 SomeDate2
1 Canada Ontario Type1 1 01/01/2009 02/02/2009 03/03/2009
2 Canada Ontario Type2 1 01/01/2009 02/02/2009 03/03/2009
3 Germany Berlin Type1 1 03/01/2007 02/01/2008 04/03/2006
4 Germany Berlin Type1 3 03/01/2007 02/01/2008 04/03/2006
I need the output as:
ID Country City Qty SomeDate SomeDate1 SomeDate2
1 Canada Ontario 2 01/01/2009 02/02/2009 03/03/2009
3 Germany Berlin 4 03/01/200开发者_运维问答7 02/01/2008 04/03/2006
Dates between same cities are the same.
So, how?
SELECT MIN(ID),
Country,
City,
SUM(Qty) AS Qty,
MIN(SomeDate) AS SomeDate,
MIN(SomeDate1) AS SomeDate1,
MIN(SomeDate2) AS SomeDate2
FROM sourceTable
GROUP BY Country, City;
SELECT
MIN(ID),
Country,
City,
SUM(Qty),
SomeDate,
SomeDate1,
SomeDate2
FROM
MyTable
GROUP BY
Country,
City,
SomeDate,
SomeDate1,
SomeDate2
SELECT MIN(ID), Country, City, SUM(Qty), MIN(SomeDate), MIN(SomeDate1), MIN(SomeDate2)
FROM myTable
GROUP BY Country, City
SELECT MIN(ID) AS ID, Country, City, SUM(Qty) AS Qty, SomeDate, SomeDate1, SomeDate2
FROM Table
Group BY Country, City, SomeDate, SomeDate1, SomeDate2
精彩评论