小编use*_*252的帖子

PostgreSQL:当x = a和x = b时,如何从表中选择2个不同的计数

亲爱的朋友Stackoverflowers,

如何从场景中的同一个表中选择2个不同的计数:

x=a and x=b
Run Code Online (Sandbox Code Playgroud)

具体来说,(WHEN type = subdomain)AND(WHEN subtype = subdomain)?

将它们添加到一起以创建'totalcount'?

我的尝试(供你参考):

SELECT description, type, count(1), subtype, count(2) 
FROM mapping, (dotcom WHERE type = subdomain) AS typecount, 
     (dotcom WHERE subtype = subdomain) AS subtypecount 
GROUP BY description, type, subtype 
HAVING count(1)>1 
AND count(2)>1 
ORDER BY count(*) 
DESC LIMIT 10
Run Code Online (Sandbox Code Playgroud)

第二次尝试:

SELECT description
FROM mapping, SUM(WHEN subdomain = type OR subdomain = subtype) AS count(1)
GROUP BY description, type, subtype 
HAVING count(1)>1 
ORDER BY count(*) 
DESC LIMIT 10
Run Code Online (Sandbox Code Playgroud)

sql postgresql count where having

5
推荐指数
1
解决办法
234
查看次数

标签 统计

count ×1

having ×1

postgresql ×1

sql ×1

where ×1