SELECT * FROM (SELECT id,ach,'X' AS counter,'A' AS class,date FROM tablename1 as t1 WHERE 1 UNION SELECT id,ach,counter,'B' AS class,date FROM tablename2 as t2 WHERE 1) AS tall order by date asc
建议增加条件,且为索引字段.其次查的数据量不能太大,不然临时表会占据较多的内存空间.宁可牺牲硬盘空间,也不要无谓的牺牲内存空间.
从长远角度来说,建议整合2个表.
select t.authorid,t.author,COUNT(t.authorid) AS authornum from(select authorid,author,time from 表1union allselect authorid,author,time from 表2) twhere t.time >$time GROUP BY t.authorid,t.author ORDER BY authornum DESC基本就这样。表名你换成你自己的表名,我这里分别用表1和表2表示的
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)