日期:2014-05-17 浏览次数:20420 次
CREATE TABLE #ta (NAME VARCHAR(8),AGE INT ,SCORE INT,ID INT IDENTITY(1,1))
go
INSERT INTO #ta (NAME,AGE,SCORE)
SELECT '张三',23,100 UNION ALL
SELECT '张三',23,99 UNION ALL
SELECT '张三',23,91 UNION ALL
SELECT '王五',24,55 UNION ALL
SELECT '赵六',23,null
go
--查詢
SELECT
CASE
WHEN EXISTS(SELECT 1 FROM #ta WHERE NAME=a.NAME AND ID<a.ID) THEN NULL
ELSE NAME
END NAME,AGE,SCORE
FROM #ta a
ORDER BY id