4类分别在不用的4账表里
如果数据某页数据全齐满足 A类(3条) B类(5条) C类(5条)D类(17条) 的数量
排列顺序应该是 1A 2D 3B 4C 5A 6D 7B 8C 9A 10D 11B 12C 13D 14C 15D 16B 17D 18C 19D 20D 21B 22D 23D......30D
如果某类在N也条数不符合上述规则 则整体向上递排 用D类补足
若描述不清楚请大哥老师 提示
希望提供个思路 小弟自己去实践
若用到函数和存储过程,大概示意下就好
另外这个问题能否用SQL完全实现 如果不能完全实现 请提供个配合后端解决的方案
谢谢
------解决思路----------------------
楼主看看下面的思路是不是你想要的:
select top 30
A
from (
select top 3
A
from tableA
union all
select top 5
B
from tableB
union all
select top 5
C
from tableC
union all
select
D
from tableD
) List
------解决思路----------------------
自己添加排序字段
select top 30
[类]
from (
select top 3
A as [类], 1 as idx, ROW_NUMBER() OVER(order by id) as idy
from tableA
union all
select top 5
B, 3 as idx, ROW_NUMBER() OVER(order by id) as idy
from tableB
union all
select top 5
C, 4 as idx, ROW_NUMBER() OVER(order by id) as idy
from tableC
union all
select
D, 2 as idx, ROW_NUMBER() OVER(order by id) as idy
from tableD
) List
order by idy, idx