0
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

4

2 回答 2

1

如何client_ID使用MAX()or聚合列MIN()

SELECT MAX(client_id) client_id, Rad_ID
FROM   Client_registration
GROUP  BY Rad_ID
ORDER  BY client_id, Rad_ID
于 2013-03-28T07:27:00.923 回答
0

它应该是

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

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

于 2013-03-28T07:01:00.387 回答