简体   繁体   English

MySQL从查询创建表

[英]MySQL Create Table from Query

I have a large table with what are essentially log entries. 我有一个大的表,里面基本上是日志条目。 For most of my queries, I need a table with the most recent entries, so I created a 'view' from the following query: 对于大多数查询,我需要一个包含最新条目的表,因此我从以下查询创建了“视图”:

SELECT t1.store_id, t1.code_id, t1.working, t1.expiration, t1.details, t1.price
    FROM code_stores t1
    LEFT OUTER JOIN code_stores t2
    ON (t1.store_id = t2.store_id AND t1.code_id = t2.code_id AND t1.id < t2.id)
    WHERE t2.store_id IS NULL

Then I use this 'view' in my query. 然后在查询中使用此“视图”。 Unfortunately this is leading to slow queries, so I'd like to cache the results of this view somehow. 不幸的是,这导致查询缓慢,因此我想以某种方式缓存该视图的结果。 Since this view will only change a few times a day (when I can run a query to update the cache table), I would like to create a temporary table that stores the results of this view, and update this throughout the day. 由于此视图每天只会更改几次(当我可以运行查询以更新缓存表时),因此,我想创建一个临时表来存储该视图的结果,并在一天内进行更新。

How do I go about doing this? 我该怎么做呢? I read about materialized views, but it appears that they don't work with mysql. 我读过有关物化视图的信息,但看来它们不适用于mysql。 More help would be greatly appreciated. 更多帮助将不胜感激。

关于使用临时表的想法,我建议使用触发器,以便每次code_store表更改时都会更新临时表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM