oracle表中重复的总数

时间:2012-08-27 13:41:12

标签: sql oracle count duplicates

我有一张如下表格

SUBJECT Years MARKS
AB      1       20
AB      1       25
AC      1       20
AC      1       30
AC      1       40
AD      1       20

我只需要重复数(主题||年),预期答案是2 而不是

AB1 -- 2
AC1 -- 3

3 个答案:

答案 0 :(得分:7)

这将是重复查询...

之上的另一个查询
select subject, year, count(*)
  from table1
  group by subject, year
  having count(*) > 1

将为您提供计数的所有结果。另一个指望......

select count(*)
  from (
select subject, year, count(*)
  from table1
  group by subject, year
  having count(*) > 1
) 

应该为您提供具有一个或多个重复项的记录数。

答案 1 :(得分:1)

select subject,years, count(*)
from table
group by subject,years
having count (*) > 1;

答案 2 :(得分:0)

只需使用内嵌视图查看您用于获取示例的查询(AB1,AC1),如下所示:

select count (*) from (select subject, years from t group by subject, years having count (*) > 1)