【发布时间】:2012-03-23 20:42:32
【问题描述】:
我有这张桌子
create table student (
stu_id int,
s_name nvarchar(max),
s_subject nvarchar(max),
)
这是数据
insert into student values(123,'pammy','English');
insert into student values(123,'pammy','Maths');
insert into student values(123,'pammy','Chemistry');
insert into student values(124,'watts','Biology');
insert into student values(125,'Tom','Physics');
insert into student values(125,'Tom','Computer';
insert into student values(125,'Tom','ED';
所以我想检索发生两次以上的记录。我的代码是
select stu_id,s_Name
from student
group by stu_id,s_Name
having count(stu_id) >2 ;
结果很完美。
但是当我想要s_subject 时,它说没有选择行。我不知道为什么。
select stu_id,s_Name,s_subject
from student
group by stu_id,s_Name,s_subject
having count(stu_id) >2 ;
【问题讨论】:
-
您只需要选择主题,对吗?仅当 stu_id,s_Name 重复时才会重复,对吗?如果是这样,你想得到哪个科目?不止一个...