美文网首页
MySQL: TEMP TABLE

MySQL: TEMP TABLE

作者: 0_Eric | 来源:发表于2017-05-09 18:41 被阅读0次

SELECT cust.name,rcVBles.balance,……other columns 

FROM cust,rcvbles 

WHERE cust.customer_id = rcvlbes.customer_id 

AND rcvblls.balance>0 

AND cust.postcode>“98000” 

ORDER BY cust.name

可以把balance >0的所有行都找出来,并按名字排序:

SELECT cust.name,rcvbles.balance,……other columns 

FROM cust,rcvbles 

WHERE cust.customer_id = rcvlbes.customer_id 

AND rcvblls.balance>0 

ORDER BY cust.name 

INTO TEMP cust_with_balance

然后以下面的方式在临时表中查询:

SELECT * FROM cust_with_balance 

WHERE postcode>“98000”

临时表比主表的行少,而且物理顺序可以自定义,减少了磁盘I/O,也大幅减少了查询的工作量。

Note:临时表创建后不会反应主表的变化,如果主表中数据频繁修改的情况下,不建议使用。

相关文章

网友评论

      本文标题:MySQL: TEMP TABLE

      本文链接:https://www.haomeiwen.com/subject/xwsitxtx.html