【发布时间】:2020-07-24 08:08:43
【问题描述】:
我尝试在 SQL 笔记本中使用以下语法创建表,但不断收到错误消息,例如:“ Expected list-item:” 我的代码:
create table
player_info as
(
select distinct id,
name,
sex,
age,
case(when height is NULL then floor(avg(height)) else height end) as Hght,
case(when weight is NULL then floor(avg(weight)) else weight end ) as Wght,
team as country,
city
from athlete_events
group by id,
name,
sex,
age
)
例如,我想使用主数据集中的 select 子句中提到的字段创建一个表,以便我可以 删除 NULL 值。预期的输出应该是一个表,其中年龄、身高和体重列中没有空值。
已编辑:我找到了这个问题的解决方案,它实际上是括号,它是 case 语句和 select 子句的问题,它不应该包含在括号中,它认为这是子查询的一部分。此外,考虑到我使用“NA”作为该列的 dtype 的条件是 TEXT。代码应如下所示:
create table
player_info as
select distinct id,
name,
sex,
age,
(case when height ='NA' then floor(avg(height)) else height end) as Hght,
(case when weight ='NA' then floor(avg(weight)) else weight end ) as Wght,
team as country,
city
from athlete_events
group by id,
name,
sex,
age
【问题讨论】:
-
错误信息:'expected-list: '
-
更新您的问题添加适当的数据样本和预期的结果..
标签: sql database sqlite data-analysis create-table