我正在尝试让SQL在列中找到苹果的总数" fruits"从表A中,将总计数插入一列 ("总成果")在表B中,但不能正确的措辞。
此语句返回10,
SELECT COUNT ("fruits")
FROM grocery_list
WHERE "fruits" = ('Apples');
但不知道如何将结果移到表B中的列?
答案 0 :(得分:1)
据推测,您需要update
或insert
。我可能会推测:
update b
set cnt = (select count(*) from grocery_list where fruits = 'Apples')
where . . .;
where
条件指定应更新哪一行。
答案 1 :(得分:0)
请尝试插入插入:
INSERT INTO B SET "total fruits" = SELECT COUNT ("fruits") FROM grocery_list WHERE "fruits" = ('Apples');
更新:
UPDATE B SET "total fruits" = SELECT COUNT ("fruits") FROM grocery_list WHERE "fruits" = ('Apples');