我正在寻找实现以下目标的 SQL 语句:
我有一个类似 {ida | 的表idb |计数 |直接
我想将行插入到表中,从另一个表中获取 ids a 和 b,count 和 direct 是给定的值。我试过这样的事情:
不工作:
INSERT INTO my_tbl (ida, idb, count, direct)
SELECT id FROM other_tbl WHERE word ='test'
UNION
SELECT id FROM other_tbl WHERE word ='tost' 23, 5;
提前致谢。
最佳答案
这是你想要的吗?
INSERT INTO my_tbl (ida, idb, count, direct)
SELECT o1.id, o2.id, 23, 5
FROM other_tbl o1 JOIN
other_tbl o2
ON o1.word = 'test' AND o2.word = 'tost';
关于sql - PostgreSQL INSERT INTO WITH 多个 SELECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51456319/