我有一个条目表:id,name
用户可以根据需要输入多次。
我想检索已输入2次的用户总数。
所以如果表格如下:
user_id name
------- ----
3 chuck
4 larry
5 george
3 chuck
4 larry
查询将返回2,因为user_id 3和4是唯一在条目表中有两个条目的用户。
答案 0 :(得分:1)
使用count(*)
方法
select userid,count(*) as count
from (select count(*) as c,userid
from entries
here c>=2 group by user_id)
as dummy_table
答案 1 :(得分:1)
试试这个:
SELECT count(*)
FROM
(
SELECT count(*) as count
FROM table_name
GROUP BY name
HAVING count = 2
)
答案 2 :(得分:1)
试试这个:
select user_id , count(name) as c from table_name GROUP BY user_id having count(*) = 2