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重複時纔有重複,對嗎?如果是這樣,你想得到哪個科目?有不止一個... – 2012-03-06 11:25:16