我正在尝试创建一个具有 3 个状态的分类列:subA、subB 或两者都不是。
我正在使用 SqliteStudio 3.1.0、RHEL7.0。
我通过 Python/Pandas 将我的 csv 加载到 SQLITE 中。一切都按预期工作。
我在 GUI 中添加了约束:
"fullpath" TEXT Unique NOT NULL.
Run Code Online (Sandbox Code Playgroud)
我Sub
在 SqiteStudio 中添加了列并在数据表中仔细检查。
alter table data add column Sub text(100)
Run Code Online (Sandbox Code Playgroud)
这有效,没有给出错误。然后我尝试:
insert into data(Sub)
select fullpath, case
when fullpath like "%subA%" then "subA"
when fullpath like "%subB%" then "subB"
else "Neither" end
from data
Run Code Online (Sandbox Code Playgroud)
我收到这个我不明白的错误。
[18:35:45] Error while executing SQL query on database 'test': 2 values for 1 columns
Run Code Online (Sandbox Code Playgroud)
您正在执行一项操作,insert into
但您只指定了一个字段(子),然后您选择了 2 个字段,正如错误消息所述。
insert into data(Sub) -- only one field
select fullpath, case -- 2 fields
when fullpath like "%subA%" then "subA"
when fullpath like "%subB%" then "subB"
else "Neither" end
from data
Run Code Online (Sandbox Code Playgroud)
您需要向数据表添加一个完整路径字段并执行以下操作:
insert into data(fullpath, Sub)
select fullpath, case
when fullpath like "%subA%" then "subA"
when fullpath like "%subB%" then "subB"
else "Neither" end
from data
Run Code Online (Sandbox Code Playgroud)
或者您需要选择一列
insert into data(Sub)
select case
when fullpath like "%subA%" then "subA"
when fullpath like "%subB%" then "subB"
else "Neither" end
from data
Run Code Online (Sandbox Code Playgroud)