从表中找到不同的R_ID

时间:2013-03-28 06:58:39

标签: sql sql-server tsql select

Create table Client_Registration
(
    Client_ID int,
    Rad_ID int 
);

INSERT INTO Client_Registration (Client_ID,Rad_ID)
VALUES ('1','1');
INSERT INTO Client_Registration (Client_ID,Rad_ID)
VALUES ('2','1');
INSERT INTO Client_Registration (Client_ID,Rad_ID)
VALUES ('3','2');
INSERT INTO Client_Registration (Client_ID,Rad_ID)
VALUES ('4','2');
INSERT INTO Client_Registration (Client_ID,Rad_ID)
VALUES ('1','1');

select client_id,distinct Rad_ID from Client_registration
ORDER BY client_id, Rad_ID;

我必须从表

中找到不同的R_ID

2 个答案:

答案 0 :(得分:1)

如何使用client_IDMAX()汇总列MIN()

SELECT MAX(client_id) client_id, Rad_ID
FROM   Client_registration
GROUP  BY Rad_ID
ORDER  BY client_id, Rad_ID

答案 1 :(得分:0)

应该是

SELECT DISTINCT client_id, Rad_ID
FROM Client_registration
ORDER BY client_id, Rad_ID

请注意,没有分号。 SQL Server不需要分号。