我正在尝试取得
的结果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
答案 0 :(得分:0)
我希望您需要合并这些查询并需要一个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