如何将连接的字符串拆分为新列
How can I split a concatenated string to a new column
我有一个包含连接字符串的列。我想将它们拆分到一个新列中。
Work Rate
Medium / High
Medium / Medium
Medium / Medium
High / Medium
Medium / Medium
Medium / Low
Medium / Low
Low / High
High / High
Medium / Medium
High / Low
我找到了类似的东西。但它不会创建列。另外,作为第二个问题,我可以从这样的查询创建一个列吗?
SELECT *,split_part("Work_Rate",'/',1) as attack_work,
split_part("Work_Rate",'/',2) AS defence_work FROM "Football";
您需要:
BEGIN;
ALTER TABLE "Football" ADD COLUMN attack_work varchar;
ALTER TABLE "Football" ADD COLUMN defence_work varchar;
COMMIT; --Or ROLLBACK; if it fails
然后:
BEGIN;
UPDATE
"Football"
SET
attack_work = split_part("Work_Rate",'/',1),
defence_work = split_part("Work_Rate",'/',2);
COMMIT; --Or ROLLBACK; if it fails
我有一个包含连接字符串的列。我想将它们拆分到一个新列中。
Work Rate |
---|
Medium / High |
Medium / Medium |
Medium / Medium |
High / Medium |
Medium / Medium |
Medium / Low |
Medium / Low |
Low / High |
High / High |
Medium / Medium |
High / Low |
我找到了类似的东西。但它不会创建列。另外,作为第二个问题,我可以从这样的查询创建一个列吗?
SELECT *,split_part("Work_Rate",'/',1) as attack_work,
split_part("Work_Rate",'/',2) AS defence_work FROM "Football";
您需要:
BEGIN;
ALTER TABLE "Football" ADD COLUMN attack_work varchar;
ALTER TABLE "Football" ADD COLUMN defence_work varchar;
COMMIT; --Or ROLLBACK; if it fails
然后:
BEGIN;
UPDATE
"Football"
SET
attack_work = split_part("Work_Rate",'/',1),
defence_work = split_part("Work_Rate",'/',2);
COMMIT; --Or ROLLBACK; if it fails