-2

i have a table name as testtabl1 now
i want to find all the student who are enroll in 2 or more courses,
in this sid is the student id and cid is the course id

table structure

create table testtabl1(Sid int,cid int,years varchar(20))
insert into testtabl1(Sid,cid,years)
select 1,1,'2016'
union all
select 2,2,'2017'
union all
select 1,2,'2017'

new to sql server and stackoverflow need help !!

tried

select sid,COUNT(*),cid from testtabl1 group by sid,cid having count(*)>1
Deepak Jain
  • 137
  • 1
  • 3
  • 27

1 Answers1

0
SELECT sid as StudentId,
       COUNT(cid) as SelectedCoursesCount
FROM testtabl1
GROUP BY sid
HAVING COUNT(cid) > 1;
Stix
  • 455
  • 5
  • 16