日期:2014-05-19  浏览次数:20475 次

用查詢語句實現流水號字段,如何做
效果如下:
f1       f2         f3
a         b           0001
c         d           0002
e         f           0003
a         g           0004

要求:隻能用select語句。

------解决方案--------------------
select rigth( '000 ' + ltrim(cast(max(f3) as int) + 1), 4) from table
------解决方案--------------------
echiynn(寶琲) ( ) 信誉:100 Blog 加为好友 2007-07-12 09:52:12 得分: 0


select rigth( '000 ' + ltrim(cast(max(f3) as int) + 1), 4) from table



----------
你這樣只能到0009,再後面的就不行了
------解决方案--------------------
select f1,f2,(select right(10000+count(1),4) from tb where f2 <=a.f2) f3 from tb a order by f3
------解决方案--------------------
select cast(id as int) from t1