获取 SQL 中不同值的计数
我有一张总共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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)