4

I have a table like below

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

I only need count of duplicates (subject||Year), expected answer is 2 and not

AB1 -- 2
AC1 -- 3
Florin Ghita
  • 17,525
  • 6
  • 57
  • 76
user1627796
  • 53
  • 1
  • 1
  • 5

3 Answers3

8

That would be one more query on top of the duplicates query...

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

will give you all the results with counts. Another count over this..

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

should give you the number of records which have one or more duplicates.

Rajesh Chamarthi
  • 18,568
  • 4
  • 40
  • 67
1
select subject,years, count(*)
from table
group by subject,years
having count (*) > 1;
vikiiii
  • 9,246
  • 9
  • 49
  • 68
0

Just use an inline view over the query you used to get your example (AB1, AC1) like this:

select count (*) from (select subject, years from t group by subject, years having count (*) > 1)
Lord Peter
  • 3,433
  • 2
  • 33
  • 33