【发布时间】:2019-09-24 16:10:20
【问题描述】:
我有一个 PostgreSQL 表,其中包含几列 col1、col2、col3、col4。我想计算 col3 中有多少行唯一值。结果也需要显示行数和值。我如何形成这样的查询。我正在使用 PgAdmin4。
col1. col2. col3. col4.
x1 y1 123 xx-xx-xxxx
x2 y2 123 xx-xx-xxxx
x3 y3 123 xx-xx-xxxx
x4 y4 111 xx-xx-xxxx
x5 y5 111 xx-xx-xxxx
我尝试使用select count( distinct col3) from table_ where col3_ts >'2019-09-17'
但它仅计算/显示所有不同行的数量,即仅像 8999 这样的数字。
示例结果如下:
#. col3. # of rows.
-----------------------
1. 123 3
2. 111 2
-----------------------
【问题讨论】:
-
请分享一些例子。
-
@jjanes:我尝试添加示例。我希望它会有所帮助。
-
你不需要不同的计数,你只需要按 count() 分组。
标签: postgresql