我想计算一列中的项目只出现一次的次数。例如,如果在我的桌子上我有...
Name
----------
Fred
Barney
Wilma
Fred
Betty
Barney
Fred
...它会返回 2,因为只有 Wilma 和 Betty 出现过一次。
select count(*) from
(select count(*) from Table1
group by Name
having count(*) =1) s
以下是您可以尝试的查询:
select count(*) from
(select Name
from Table1
group by Name
having count(*) = 1) T
直到上面我的帖子是为你的实际帖子。
在 oracle 中,您可以尝试以下查询:
select sum(count(rownum))
from Table1
group by "Name"
having count(*) = 1
或者
SELECT COUNT(*)
FROM Table1 a
LEFT JOIN Table1 b
ON a.Name=b.Name
AND a.%%physloc%% <> b.%%physloc%%
WHERE b.Name IS NULL
或者
在 Sybase 中,您可以尝试以下查询:
select count(count(name))
from table
group by name
having count(name) = 1
根据@user2617962 的回答。
谢谢
由于您只需要出现一次的列值计数而没有列的实际值,因此查询应该是:
select count(count(name)) from table group by name having count(name) = 1
尝试跟随。
select name from (select name, count(name) as num from tblUsers group by name)
tblTemp where tblTemp.num=1
如果可行,请标记它.. :)