MySQL: TEMP TABLE

2017-05-09  本文已影响0人  0_Eric

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:临时表创建后不会反应主表的变化,如果主表中数据频繁修改的情况下,不建议使用。

上一篇 下一篇

猜你喜欢

热点阅读