sql使数据库中重复数据id雷同
sql使数据库中重复数据id相同
id StartData Comment3 Title
1 2014/06/20 test1 title1
2 2014/06/20 test 2 title2
3 2014/06/20 test 3 title11
4 2014/06/21 test 4 title
我需要的结果是:
newid StartData Comment3 Title
1 2014/06/20 test1 title1
1 2014/06/20 test 2 title2
1 2014/06/20 test 3 title11
2 2014/06/21 test 4 title
------解决方案--------------------
id StartData Comment3 Title
1 2014/06/20 test1 title1
2 2014/06/20 test 2 title2
3 2014/06/20 test 3 title11
4 2014/06/21 test 4 title
我需要的结果是:
newid StartData Comment3 Title
1 2014/06/20 test1 title1
1 2014/06/20 test 2 title2
1 2014/06/20 test 3 title11
2 2014/06/21 test 4 title
------解决方案--------------------
DECLARE @T TABLE
( id int,
StartData datetime,
Comment3 varchar(10),
Title varchar(10))
INSERT INTO @T
SELECT 1,'2014/06/20','test1','title1' UNION ALL
SELECT 2,'2014/06/20','test 2','title2' UNION ALL
SELECT 3,'2014/06/20','test 3','title11' UNION ALL
SELECT 4,'2014/06/21','test 4','title'
SELECT DENSE_RANK()OVER(ORDER BY StartData)AS [Newid],
StartData,
Comment3,
Title
FROM @T
**************************************************************
1 2014-06-20 00:00:00.000 test1 title1
1 2014-06-20 00:00:00.000 test 2 title2
1 2014-06-20 00:00:00.000 test 3 title11
2 2014-06-21 00:00:00.000 test 4 title
**************************************************************