IF OBJECT_ID(‘TABMAXID‘) IS NOT NULL DROP TABLE TABMXID GO CREATE TABLE TABMXID( ID INT IDENTITY(1,1) PRIMARY KEY, NAME VARCHAR(50) NOT NULL, NUM INT NOT NULL ) GO INSERT INTO TABMXID(NAME,NUM)VALUES(1,2) INSERT INTO TABMXID(NAME,NUM)VALUES(1,3) INSERT INTO TABMXID(NAME,NUM)VALUES(2,1) INSERT INTO TABMXID(NAME,NUM)VALUES(2,2) INSERT INTO TABMXID(NAME,NUM)VALUES(3,3) INSERT INTO TABMXID(NAME,NUM)VALUES(3,4) GO SELECT * FROM dbo.TABMXID GO SELECT NAME,MAX(NUM) AS NUM FROM dbo.TABMXID GROUP BY NAME
时间: 2024-10-05 12:37:15