开发者

Count distinct group by SQL code?

开发者 https://www.devze.com 2023-03-12 08:33 出处:网络
say I had just 2 columns of data.... Postcode Sold date LE14 6QR 01/01/2011 How could I say...display for each postcode the d开发者_StackOverflow社区ate for each time a house in that area has been

say I had just 2 columns of data....

Postcode Sold date
LE14 6QR 01/01/2011

How could I say...display for each postcode the d开发者_StackOverflow社区ate for each time a house in that area has been sold.

E.G If that postcode occurs 14 times, it would list each of the dates?

Thanks,


From you description it sounds like you want to list the contents of the table, so you can do:

select Postcode, [Sold date]
from MyTable

If you do not want duplicate dates, you can do:

select Postcode, [Sold date]
from MyTable
group by Postcode, [Sold date]


If you're going to group then you should also COUNT just to make sure you're totals are adding up.

SELECT PostCode, [Sold Date], COUNT(PostCode)
FROM [table]
GROUP BY PostCode, [Sold Date]
ORDER BY COUNT(PostCode) DESC


I think this is what you want:

SELECT PostCode, SoldDate
FROM YourTable
Group By PostCode
0

精彩评论

暂无评论...
验证码 换一张
取 消