我现在有一个表名为testtabl1
我想找到所有参加2门或更多课程的学生,
在这个sid
是学生id和cid
是课程id
表结构
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'
新的SQL Server和stackoverflow需要帮助!!
试着
select sid,COUNT(*),cid from testtabl1 group by sid,cid having count(*)>1
SELECT sid as StudentId,
COUNT(cid) as SelectedCoursesCount
FROM testtabl1
GROUP BY sid
HAVING COUNT(cid) > 1;