有一个方法你可以参考一下,把日期加进去,加个参数取每天日期。然后按日期编号,然后把编号错位后再union all起来,按照新序号排序。
SELECT bb.* from (
select lag(aa.序号,1,0) over(order by aa.序号)+aa.序号 as 错位序号,aa.* from (
select row_number() OVER(order by a.销量 ) as 序号,a.*
from (
select 'A1' as 商品,12 as 销量,22 as 到货量,15 as 到货时间
union all
select 'A2' as 商品,15 as 销量,15 as 到货量,16 as 到货时间
union all
select 'A3' as 商品,20 as 销量,16 as 到货量,17 as 到货时间
union all
select 'A4' as 商品,12 as 销量,22 as 到货量,15 as 到货时间
union all
select 'A5' as 商品,15 as 销量,15 as 到货量,16 as 到货时间
union all
select 'A6' as 商品,20 as 销量,16 as 到货量,17 as 到货时间
) a
) aa
UNION ALL
select aa.序号 * 2 as 错位序号,aa.* from (
select row_number() OVER(order by a.销量 ) as 序号,a.*
from (
select 'B1' as 商品,12 as 销量,22 as 到货量,15 as 到货时间
union all
select 'B2' as 商品,15 as 销量,15 as 到货量,16 as 到货时间
union all
select 'B3' as 商品,20 as 销量,16 as 到货量,17 as 到货时间
union all
select 'B4' as 商品,12 as 销量,22 as 到货量,15 as 到货时间
union all
select 'B5' as 商品,15 as 销量,15 as 到货量,16 as 到货时间
union all
select 'B6' as 商品,20 as 销量,16 as 到货量,17 as 到货时间
) a
) aa
) bb order by bb.错位序号