Py学习  »  DATABASE

MySQL临时表有Case语句问题

mjasilver • 5 年前 • 1703 次点击  

我正试图通过命令提示符在MySQL 8.0中创建一个临时表。select语句本身正确地返回值,但是当它被放入 CREATE TEMPORARY TABLE 声明,我得到一个错误。

我尝试了很多事情,从改变语法到其他insert语句。找不到解决方案。感谢所有能帮忙的人。

create temporary table tempTable 
select game_date
,home_team
,inning
,inning_topbot
, 'innType'=case when   inning_topbot='top' then away_score   
   else home_score   
   end 
from pitchdata;
ERROR 1166 (42000): Incorrect column name ''innType'=case when   inning_topbot='top' then away_score   else home_score   end'
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/51634
 
1703 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Gordon Linoff
Reply   •   1 楼
Gordon Linoff    6 年前

你的语法没有意义。也许这就是你的意图:

create temporary table tempTable as
    select game_date, home_team, inning, inning_topbot, 
           (case when inning_topbot = 'top' then away_score
                 else home_score
            end) as innType
    from pitchdata;