为什么我不能创建临时表然后立即加入它?
\n\nmysql> 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);\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n\n\n查询正常,57149 行受影响(0.14 秒)\n 记录:57149 重复:0 警告:0
\n
mysql> select T.tweet_id, T.favorite_count, T.retweet_count, T2.C from \n-> tweets AS T JOIN table2\xc2\xa0AS T2 \n-> on T.tweet_id = T2.in_reply_to_id;\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n\n\n错误 1146 (42S02): 表 'twitter_analysis.table2\xc2\xa0as' 不存在\n mysql>
\n
但它确实存在,因为我可以从中选择!
\n\nselect count(*) from table2;\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n\n\n\n57149 1 行一组(0.01 秒)
\n
这个错误非常令人沮丧。\n有没有办法将此临时表放入选择查询中?
\n你可以像这样把它放在查询中
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;
Run Code Online (Sandbox Code Playgroud)
您可以尝试从临时表中进行选择并将另一个表加入其中。
| 归档时间: |
|
| 查看次数: |
8553 次 |
| 最近记录: |