一列中同记录的值只显示第一条,求SQL
本帖最后由 autoel 于 2013-04-18 10:24:23 编辑
求一条SQL, A,B两列, 对A列重复字段只显示第一条
A B
SSS 0
SSS 0
SSS 0
BAC 0
BAC 0
DDD 0
实现结果如下:
A B
SSS 0
0
0
BAC 0
0
DDD 0
SQL
------解决方案--------------------SELECT CASE WHEN row_id = 1 THEN [a]
ELSE ''
END
, [B]
FROM (
SELECT * , ROW_NUMBER ()OVER (PARTITION BY [A] ORDER BY GETDATE()) AS row_id FROM #tb
) t