Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个表,第一个名称是“sales”,第二个名称是“items”,两个表都有相同的列“code”和“qtd”;我想编写 MYSQL 查询女巫,我需要两个表中的 sum(qtd),其中两个表中的代码相同。对于单表我正在使用这个
“按代码从销售组中选择代码,总和(qtd)”;
尝试这个:
Select code, sum(qtd) from ( select code, qtd from sales union all select code, qtd from items) as innerTable group by code