当前位置: 代码迷 >> ASP.NET >> 这样的SQL语句有人会吗?请高手帮忙下!解决方案
  详细解决方案

这样的SQL语句有人会吗?请高手帮忙下!解决方案

热度:9890   发布时间:2013-02-25 00:00:00.0
这样的SQL语句有人会吗?请高手帮忙下!
888000 919633574558315468750 2008-09-19 21:17:11.547 NULL
888000 919633574558400156250 2008-09-19 21:17:20.017 2008-09-19 21:17:20.017
888000 919633574560137812500 2008-09-19 21:20:13.780 2008-09-19 21:20:13.780
888000 919633574560213750000 2008-09-19 21:20:21.377 2008-09-19 21:20:21.377
888000 919633574560485937500 2008-09-19 21:20:48.593 2008-09-19 21:20:48.593

我想要的效果是
888000 919633574558315468750 2008-09-19 21:17:11.547 NULL
919633574558400156250 2008-09-19 21:17:20.017 2008-09-19 21:17:20.017
919633574560137812500 2008-09-19 21:20:13.780 2008-09-19 21:20:13.780
919633574560213750000 2008-09-19 21:20:21.377 2008-09-19 21:20:21.377
919633574560485937500 2008-09-19 21:20:48.593 2008-09-19 21:20:48.593
可以实现吗

------解决方案--------------------------------------------------------
SQL code
--> Test Data: @Tdeclare @T table (id int identity(1,1), [c1] int,[c2] numeric(21,0),[c3] datetime,[c4] datetime)insert into @Tselect 888000,919633574558315468750,'2008-09-19 21:17:11.547',null union allselect 888000,919633574558400156250,'2008-09-19 21:17:20.017','2008-09-19 21:17:20.017' union allselect 888000,919633574560137812500,'2008-09-19 21:20:13.780','2008-09-19 21:20:13.780' union allselect 888000,919633574560213750000,'2008-09-19 21:20:21.377','2008-09-19 21:20:21.377' union allselect 888000,919633574560485937500,'2008-09-19 21:20:48.593','2008-09-19 21:20:48.593'select * from @T--Codeselect c1=case when exists(select 1 from @T where c1 = a.c1 and id < a.id) then '' else ltrim(c1) end,c2,c3,c4 from @T a--Drop--Result/*c1           c2                                      c3                      c4------------ --------------------------------------- ----------------------- -----------------------888000       919633574558315468750                   2008-09-19 21:17:11.547 NULL             919633574558400156250                   2008-09-19 21:17:20.017 2008-09-19 21:17:20.017             919633574560137812500                   2008-09-19 21:20:13.780 2008-09-19 21:20:13.780             919633574560213750000                   2008-09-19 21:20:21.377 2008-09-19 21:20:21.377             919633574560485937500                   2008-09-19 21:20:48.593 2008-09-19 21:20:48.593*/
  相关解决方案