我使用UNION ALL
从不同的表中获取值。
我的代码如下。
SELECT DISTINCT datei, amount FROM
(
SELECT datei, amount, 1 AS identification FROM income
UNION ALL
SELECT datee, amount, 2 AS identification FROM expense
UNION ALL
SELECT date, amount, 3 AS identification FROM others
) t
ORDER BY `datei` ASC
但是我希望它是distinct
日期。
那我该怎么办呢?
提前谢谢。
答案 0 :(得分:1)
要获得单日金额,您可以使用以下查询
yerr
答案 1 :(得分:0)
SELECT datei, sum(amount)
FROM
(
SELECT datei, amount, 1 AS identification FROM income
UNION ALL
SELECT datee, amount, 2 AS identification FROM expense
UNION ALL
SELECT date, amount, 3 AS identification FROM others
) t
GROUP BY datei
ORDER BY datei ASC