获取 SQL 中不同值的计数

发布于 01-18 07:28 字数 332 浏览 2 评论 0原文

我有一张总共23行的桌子。其中一列称为thing。在总计23行中,只有11个不同的事情。

当我运行时:

SELECT DISTINCT thing FROM tablename WHERE condition

我正确地得到11行。

但是,当我跑步时:

SELECT DISTINCT COUNT(thing) FROM tablename WHERE condition

总数得到23。但是,我想获得11,这是不同事物的数量。我如何重写我的查询,以使我总数为11?

I have a table with 23 total rows. One of the columns is called thing. There are only 11 distinct things out of the 23 total rows.

When I run:

SELECT DISTINCT thing FROM tablename WHERE condition

I correctly get 11 rows.

However, when I run:

SELECT DISTINCT COUNT(thing) FROM tablename WHERE condition

I get 23 for the total count. However, I want to get 11, which is the count of the distinct things. How can I rewrite my query so that it gives me a total count of 11?

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

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

发布评论

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

评论(1

甜点2025-01-25 07:28:23
SELECT COUNT(DISTINCT thing) FROM tablename WHERE condition
SELECT COUNT(DISTINCT thing) FROM tablename WHERE condition
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文