select * from A order by time desc limit 3 union all select * from B order by time desc limit 3 union all select * from C order by time desc limit 3表里面连三条数据都没有 这得什么表啊
假如c表没有记录,那么由A表和b表来取或A表足够的话也可以把c表的数量再取出来. 我昨天也试过union all 我再试一下.
按下面思路实现。 但效率极差。select * from ( (select *, (select count(*) from a where 时间>=t.时间 ) as K from A t) union all (select *, (select count(*) from a where 时间>=t.时间 ) as K from B t) union all (select *, (select count(*) from a where 时间>=t.时间 ) as K from C t)) v order by k limit 9
举例说明,假设C表没有记录,A、B表各取多少?只取A、还是B表记录 ?
union all
select * from B order by time desc limit 3
union all
select * from C order by time desc limit 3表里面连三条数据都没有 这得什么表啊
我昨天也试过union all 我再试一下.
c表没有记录,怎么取?
但效率极差。select * from
(
(select *, (select count(*) from a where 时间>=t.时间 ) as K from A t)
union all
(select *, (select count(*) from a where 时间>=t.时间 ) as K from B t)
union all
(select *, (select count(*) from a where 时间>=t.时间 ) as K from C t)) v
order by k
limit 9
在php里实现:
1、计算机每个表的总记录条数.
就有如下的数组:$aa=array(
"表1"=>20,
"表2"=>2,
"表3"=>0
);2、每次一共取9条,那么每个平均下来就取3条(假设三张表,每张表里的记录数随机)
第一次取,表1取7条,表2取2条,表3取0条.
第二次取,表一接着上一次取了的再取9条.
......这个算法我不知道怎么实现
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。