Select 字段1,...,字段n
From (Select *,(Select Count(*)
From 订单表 as a
Where a.客户ID = 订单表.客户ID
And a.订单日期>=订单表.订单日期) as 序号
From 订单表 ) as b
Where 序号<=2
其中count(*)是用于通过找出相同客户ID但晚于当前订单日期的订单数来确定当前订单的序号。
未经测试:
表:T
字段:id 自动递增,
field1 数字,
.....
select * from (
select *,(select count(*) from T as t2 where t2.field1=t1.field1 and t2.id<=t1.id) as aaa from T as t1) as t3
where aaa<=2