在现有表格中添加 SQLite 列

huangapple go评论58阅读模式
英文:

sqlite append column to existing table

问题

我有一个名为"MyTable"的表,其中有3列,分别命名为"A","B"和"C"。
现在,我使用SELECT和LENGTH函数,类似于SELECT LENGTH("A") FROM MyTable。
因此,我只是获得了另一列,其中包含了从"A"列的每一行中获取的字符长度。
然而,我不知道如何将这一列附加到MyTable。

换句话说,如果我的问题重新表述一下,我想知道如何创建另一列,其中包含特定列的字符长度。

我尝试创建一个新表,其中包括从SELECT LENGTH("A") FROM创建的列,以及CREATE新表 AS SELECT LENGTH("A") FROM。但是,它显示语法错误。

英文:

I have a table(MyTable) with 3 columns named as "A","B",and "C".
Now, I use SELECT and LENGTH function like SELECT LENGTH("A") FROM MyTable.
So, I just got another column with rows of characters length from each row of column A.
However, I have no clue to append this to MyTable.

In other words, if my question is rephrased, I wonder how to make another column with characters length of a certain column.

I tried to make new table with the column made from SELECT LENGTH("A") FROM, and CREATE new table AS SELECT LENGTH("A") FROM. But, it shows syntax error.

答案1

得分: 1

我猜你得到的错误是因为你没有为新列指定名称。你可以尝试这样做:

CREATE TABLE NewTable AS SELECT A, B, C, LENGTH(A) AS A_length FROM MyTable;

正如 @forpas 所说,你的语法错误是由一个拼写错误引起的,使用了 LENTH 而不是 LENGTH

英文:

I guess the error you are getting is because you are not specifying name for the new column. Can you try this:

CREATE TABLE NewTable AS SELECT A, B, C, LENGTH(A) AS A_length FROM MyTable;

As @forpas said, your syntax error was caused by a typo - using LENTH instead of LENGTH.

huangapple
  • 本文由 发表于 2023年2月27日 15:41:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577841.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定