我是个新手我现在有30张表(没办法就是需要这么多表不能整合)表的结构都是一样的我现在要根据一定的条件然后读取出30条记录并且按照日期把查询出来的结果进行排序我现在用的查询语句...
我是个 新手 我现在有30张表(没办法 就是需要这么多表 不能整合) 表的结构都是一样的 我现在要根据一定的条件然后读取出30条记录 并且按照日期把查询出来的结果进行排序 我现在用的查询语句类似
select * from (select a,b,c,date1 from biao1 where a="已售" order by date1)as t1
union all
select * from (select a,b,c,date1 from biao2 where a="已售" order by date1)as t1
union all
select * from (select a,b,c,date1 from biao3 where a="已售" order by date1)as t1
union all
select a,b,c,date1 from biao4 where a="已售" order by date1
然后 一直到 第30个表 我想问下 有哪位高手有方式优化下我的语句 或者有别的方法啊 特急 感激不尽啊。
select * from (select a,b,c,date1 from biao1 where a="已售" and b="轿车" order by date1 limit 30)as t1
union all
select * from (select a,b,c,date1 from biao2 where a="已售" and b="轿车" order by date1 limit 30)as t1
union all
select * from (select a,b,c,date1 from biao3 where a="已售" and b="轿车" order by date1 limit 30)as t1
union all
select a,b,c,date1 from biao4 where a="已售" and b="轿车" order by date1 limit 30
刚刚的语句有点错误 大概 就是这样的。就是 不知道 这个怎么去优化 数据库或者代码或者其他什么的 就是优化下查询 速度啦 。。。因为我现在的话这样查询的话 会很慢 我建立了一个 (b,date1)的索引 可是还是很慢的感觉
展开