Access中排序问题,急啊
select * from tt order by code,fdate,groupcode,ingroupcode
得到查询结果集
code(代号) fdate(日期) GroupCode(组号) InGroupCode(组内号)
1000 2007-04-08 1 1
1000 2007-04-08 1 2
1000 2007-04-08 2 1
1000 2007-04-08 2 2
1000 2007-04-08 3 1
1000 2007-04-09 1 1
1001 2007-04-08 1 1
1001 2007-04-08 1 2
1001 2007-04-08 2 1
1001 2007-04-08 2 2
1001 2007-04-08 3 1
1001 2007-04-09 1 1
现在我需要增加一列查询排序列
实现结果如下:
code(代号) fdate(日期) GroupCode(组号) InGroupCode(组内号) 排序号
1000 2007-04-08 1 1 1
1000 2007-04-08 1 2 2
1000 2007-04-08 2 1 3
1000 2007-04-08 2 2 4
1000 2007-04-08 3 1 5
1000 2007-04-09 1 1 6
1001 2007-04-08 1 1 1
1001 2007-04-08 1 2 2
1001 2007-04-08 2 1 3
1001 2007-04-08 3 1 4
1001 2007-04-09 1 1 5
请问在access中sql语句如何写?
解决利马结贴
[解决办法]
try to:
Select *,(Select sum(iif( (fdate=x.fdate and groupcode=x.groupcode and
InGroupCode <x.InGroupCode) or
(fdate=x.fdate and groupcode <x.groupcode ) or
(fdate <x.fdate) , 1,0) ) from t
Where code=x.code and fdate <=x.fdate )+1 as 排序号
from t as x
[解决办法]
用子查询或域函数处理都可以。
[解决办法]
厉害啊
[解决办法]
有时候 到这里来 真的很能够学到很多东西
谢谢大家了
[解决办法]
增加一列辅助列,类型为自增id
select *,(select count(*) from tt where a.id> id and a.code=code) from tt a