gpt4 book ai didi

MySQL 连接 2 个查询

转载 作者:行者123 更新时间:2023-11-29 21:52:54 24 4
gpt4 key购买 nike

我正在尝试获取结果

SELECT SUM(pont) AS totalpont
FROM
(SELECT jogador.pont from jogador,usuarios WHERE email='like' and jogador.id=usuarios.j1
UNION
SELECT jogador.pont from jogador,usuarios WHERE email='like' and jogador.id=usuarios.j2
UNION
SELECT jogador.pont from jogador,usuarios WHERE email='like' and jogador.id=usuarios.j3
UNION
SELECT jogador.pont from jogador,usuarios WHERE email='like' and jogador.id=usuarios.j4) T

SELECT mercado FROM variaveis 

进入同一个查询,两个并排的独立数据集,例如查询 1 返回 1, 2, 3, 4, 5,查询 2 返回 A, B, C。我希望结果为 1,A, 2,B, 3,C, 4,null, 5,null

最佳答案

我希望您需要合并这些查询并需要一个 SUM,因为您可以使用“AS”语法(将 Mercado 重命名为 pont),以便进行求和。

SELECT SUM(COALESCE(pont, 0)) as totalpont, SUM(COALESCE(mercado, 0)) AS totalmercado
FROM
(SELECT jogador.pont, NULL AS mercado from jogador,usuarios WHERE email='like' and jogador.id=usuarios.j1
UNION
SELECT jogador.pont, NULL AS mercado from jogador,usuarios WHERE email='like' and jogador.id=usuarios.j2
UNION
SELECT jogador.pont, NULL AS mercado from jogador,usuarios WHERE email='like' and jogador.id=usuarios.j3
UNION
SELECT jogador.pont, NULL AS mercado from jogador,usuarios WHERE email='like' and jogador.id=usuarios.j4) T
UNION
SELECT NULL AS pont, mercado FROM variaveis )T

关于MySQL 连接 2 个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33460140/

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