gpt4 book ai didi

postgresql - 重复一列,将其复制到同一行中更多相同的列

转载 作者:行者123 更新时间:2023-11-29 12:31:39 33 4
gpt4 key购买 nike

我有一个包含 3 列的表格:(ID, city,city_pop)。 我只想复制 city_pop 列 20 次。因此最终表将如下所示:(ID, city, city_pop, city_pop1, city_pop2, ...city_pop20) 具有与 city_pop 相同的值。可能吗?

最佳答案

-- CREATE TABLE cities20 AS
SELECT id,city
, city_pop AS city_pop0
, city_pop AS city_pop1
, city_pop AS city_pop2
, city_pop AS city_pop3
, city_pop AS city_pop4
, city_pop AS city_pop5
, city_pop AS city_pop6
, city_pop AS city_pop7
, city_pop AS city_pop8
, city_pop AS city_pop9
, city_pop AS city_pop10
, city_pop AS city_pop11
, city_pop AS city_pop12
, city_pop AS city_pop13
, city_pop AS city_pop14
, city_pop AS city_pop15
, city_pop AS city_pop16
, city_pop AS city_pop17
, city_pop AS city_pop18
, city_pop AS city_pop19
FROM cities
;

关于postgresql - 重复一列,将其复制到同一行中更多相同的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13158358/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com