我想在表格中插入多个计数,我的意思是从汽车和卡车中计算所有数量,并将结果插入表格中的一行。
insert into table result(A,B)
select r1,r2 from(
select count(*) from trucks where fecha='X' and name like '%X%' and name not like '%X%' as r1,
select count(*) from cars where fecha='X' and name like '%X%' and name not like '%X%' as r2
)
;
我试过但不行......我不知道为什么......
我发现我正在使用蜂巢环境并且不支持子查询
答案 0 :(得分:1)
尝试用括号括起你的两个子查询,如下所示:
INSERT INTO table result(A, B)
VALUES (
(
SELECT COUNT(*)
FROM trucks
WHERE fecha='X' AND name LIKE '%X%' AND name NOT LIKE '%X%'
),
(
SELECT COUNT(*)
FROM cars
WHERE fecha='X' AND name LIKE '%X%' AND name NOT LIKE '%X%'
)
);
答案 1 :(得分:0)
尝试这样: -
INSERT INTO destination_table (
Field_1,
Field_2
)
SELECT Field_1,
Field_2
FROM source_table;