gpt4 book ai didi

mysql - 使用分组依据显示多个表中的相同字段

转载 作者:行者123 更新时间:2023-11-30 00:35:05 25 4
gpt4 key购买 nike

Table 1
id_mkt - varchar,
point - varchar

Table 2
id_mkt - varchar,
point - varchar

这是我的代码:

//表1

SELECT * FROM data1 GROUP by id_mkt asc limit 10

//表2

SELECT * FROM data2 GROUP by id_mkt asc limit 10

result table 1:
id_mkt | point
1 | 100
2 | 200
4 | 300

result table 2:
id_mkt | point
3 | 300
2 | 400
1 | 100

我想要这样的结果:

id_mkt   | point 
1 | 200
2 | 600
3 | 300
4 | 300

感谢帮助

最佳答案

SELECT t.id_mkt, SUM(t.point) AS total FROM
(
(SELECT * FROM table2)
UNION
(SELECT * FROM table1)
) AS t
GROUP BY id_mkt;

关于mysql - 使用分组依据显示多个表中的相同字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22243766/

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