IBM Db2:在“SELECT test_score“之后找到意外的标记“as”(SQL0104N)

yi0zb3m4  于 2022-11-07  发布在  DB2
关注(0)|答案(3)|浏览(210)

我现在在使用IBM Db2查询时遇到了问题。我有下面的代码:

test_score_distribution = %sql SELECT test_score as "Test Score", count(*) as "Frequency" from INTERNATIONAL_STUDENT_TEST_SCORES GROUP BY test_score;

test_score_distribution

但是在执行时,我遇到了这个错误:
(ibm程序错误)ibm_db_dbi::程序错误:SQL结果列数失败:[IBM][CLI驱动程序][DB2/LINUXX 8664] SQL 0104 N在“SELECT test_score“后面发现意外的标记“as”。预期的标记可能包括:“和”。SQLSTATE=42601\r SQLCODE=-104 [SQL:SELECT考试分数作为考试分数,count(*)作为INTERNATIONAL_STUDENT_TEST_SCORES GROUP BY考试分数中的频率;](有关此错误的背景信息,请访问:http://sqlalche.me/e/f405)
我该怎么修呢?

avkwfej4

avkwfej41#

test_score_distribution = %sql SELECT test_score, count(*) as "Frequency" 
from INTERNATIONAL_STUDENT_TEST_SCORES 
GROUP BY test_score;
test_score_distribution

这对我来说解决了

mnowg1ta

mnowg1ta2#

我遇到了同样的问题,请尝试以下步骤:

test_score_distribution = %sql SELECT test_score, count(*) "Frequency" from INTERNATIONAL_STUDENT_TEST_SCORES GROUP BY test_score;

test_score_distribution

然后,要更改名称,可以使用以下命令:

dataframe = test_score_distribution.DataFrame()
column_names = dataframe.columns.values
column_names[0] = "Test Score"
dataframe.columns = column_names
column_names[1] = "Frequency"
dataframe.columns = column_names
dataframe

根据我的经验,使用SQL魔法命令需要删除每个查询上的空格。
您可以随时使用.DataFrame()函数保存Table,从而更加自由地工作

hfwmuf9z

hfwmuf9z3#

as:不占用空间“Test Score”将给予错误“Test_Score”将正常
考试分数分布= %sql SELECT考试分数作为“考试分数,”count(*)作为“频数”来自国际学生考试分数GROUP BY考试分数;
测试分数分布

相关问题