通过 SQL 代码计算不同组的数量?

发布于 11-14 18:57 字数 173 浏览 3 评论 0原文

说我只有 2 列数据...

Postcode Sold date
LE14 6QR 01/01/2011

我怎么说...为每个邮政编码显示该地区房屋每次出售的日期。

EG 如果该邮政编码出现 14 次,它会列出每个日期吗?

谢谢,

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 date 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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一场信仰旅途2024-11-21 18:57:22

从您的描述来看,您似乎想列出表的内容,因此您可以执行以下操作:

select Postcode, [Sold date]
from MyTable

如果您不想重复日期,则可以执行以下操作:

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

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]
樱娆2024-11-21 18:57:22

如果您要分组,那么您还应该进行计数,以确保总数相加。

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

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
ゝ偶尔ゞ2024-11-21 18:57:22

我想这就是你想要的:

SELECT PostCode, SoldDate
FROM YourTable
Group By PostCode

I think this is what you want:

SELECT PostCode, SoldDate
FROM YourTable
Group By PostCode
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文