我正在从两个表中进行查询。 表是“输入”而另一个是“输出”。 OUTPUT表中的愿望清单在出货时带有加号(“ - ”更少)。列出正面和负面的值时,这会变得更容易。
查看我的查询: http://sqlfiddle.com/#!2/93dbcb/1
(SELECT nome, data, valor FROM `financ_receita` WHERE data BETWEEN ('2012-12-01') AND ('2013-12-23'))
UNION ALL
(SELECT nome, data, valor FROM `financ_despesa` WHERE data BETWEEN ('2012-12-01') AND ('2013-12-23')) ORDER BY data ASC
financ_receita =输入。
financ_despesa = out。
答案 0 :(得分:0)
select nome,data,if(valor<0,concat(valor),concat('+',valor)) as valor from
(
(
SELECT nome, data, valor FROM `financ_receita`
WHERE data BETWEEN ('2012-12-01') AND ('2013-12-23')
)
UNION ALL
(
SELECT nome, data, valor*-1 FROM `financ_despesa`
WHERE data BETWEEN ('2012-12-01') AND ('2013-12-23')
)
ORDER BY data ASC
) as myTable where valor != 0