SELECT t.User_ID, t.Age, t.Experience_Level
FROM Users t INNER JOIN
(SELECT Age, Experience_Level
FROM Users
GROUP BY Age, Experience_Level
HAVING Count(*) > 1) d ON t.Age = d.Age AND t.Experience_Level = d.Experience_Level
測試腳本:
create table Users (
User_ID int,
Name varchar(50),
Age int,
Experience_Level int
)
insert into Users (User_ID, Name, Age, Experience_Level) values (1, 'A', 33, 1)
insert into Users (User_ID, Name, Age, Experience_Level) values (2, 'B', 37, 1)
insert into Users (User_ID, Name, Age, Experience_Level) values (3, 'C', 33, 1)
insert into Users (User_ID, Name, Age, Experience_Level) values (4, 'D', 35, 2)
insert into Users (User_ID, Name, Age, Experience_Level) values (5, 'E', 33, 1)
insert into Users (User_ID, Name, Age, Experience_Level) values (6, 'F', 35, 2)
insert into Users (User_ID, Name, Age, Experience_Level) values (7, 'G', 18, 1)
正是我在找的東西,非常感謝你,先生。 – pws5068 2010-07-02 02:13:55