MySQL无法连接临时表

MySQL无法连接临时表,mysql,Mysql,为什么我不能创建一个临时表,然后立即加入它 mysql> CREATE TEMPORARY TABLE table2 as (select in_reply_to_id, COUNT(in_reply_to_id) as C from mentions where in_reply_to_id>0 group by in_reply_to_id); 查询正常,57149行受影响(0.14秒) 记录:57149重复:0警告:0 错误1146(42S02):表'twitter_anal

为什么我不能创建一个临时表,然后立即加入它

mysql> CREATE TEMPORARY TABLE table2 as (select in_reply_to_id, COUNT(in_reply_to_id) as C from mentions where in_reply_to_id>0 group by in_reply_to_id);
查询正常,57149行受影响(0.14秒) 记录:57149重复:0警告:0

错误1146(42S02):表'twitter_analysis.table2 as'不存在 mysql>

但是它确实存在,因为我可以从中选择

select count(*) from table2;
57149一行一组(0.01秒)

这个错误非常令人沮丧。
有没有办法把这个临时表放到select查询中?

你可以这样把它放到查询中

select T.tweet_id, T.favorite_count, T.retweet_count, T2.C 
FROM tweets T 
JOIN 
(   SELECT in_reply_to_id, COUNT(in_reply_to_id) as C 
    FROM mentions 
    WHERE in_reply_to_id>0 
    GROUP BY in_reply_to_id
) T2 on T.tweet_id = T2.in_reply_to_id;

您可以尝试从临时表中进行选择,并将另一个表连接到临时表中

您可以像这样将其放入查询中

select T.tweet_id, T.favorite_count, T.retweet_count, T2.C 
FROM tweets T 
JOIN 
(   SELECT in_reply_to_id, COUNT(in_reply_to_id) as C 
    FROM mentions 
    WHERE in_reply_to_id>0 
    GROUP BY in_reply_to_id
) T2 on T.tweet_id = T2.in_reply_to_id;

您可以尝试从临时表中进行选择,并将另一个表连接到临时表中

您可以将它们放在一个查询中:

select T.tweet_id, T.favorite_count, T.retweet_count, T2.C from 
tweets T JOIN (select in_reply_to_id, COUNT(in_reply_to_id) as C from mentions where in_reply_to_id>0 group by in_reply_to_id) T2 
on T.tweet_id = T2.in_reply_to_id;

您可以将它们放在一个查询中:

select T.tweet_id, T.favorite_count, T.retweet_count, T2.C from 
tweets T JOIN (select in_reply_to_id, COUNT(in_reply_to_id) as C from mentions where in_reply_to_id>0 group by in_reply_to_id) T2 
on T.tweet_id = T2.in_reply_to_id;

@汤米:当然!很高兴我能帮忙:)你试过从临时表中选择并将tweets表加入它吗?这可能是你过去的一个变通办法trying@Tommy当然可以很高兴我能帮忙:)你试过从临时表中选择并将tweets表加入它吗?这可能是你尝试的解决办法