我想根据交易存款类型=>进行过滤transactions.type以及如何在此查询中加入另一个表?
SELECT
calendar.datefield AS DATE,
Ifnull(Sum(transactions.deposit_amount), 0) AS total_deposits,
transactions.type
FROM transactions
RIGHT JOIN calendar
ON (Date(transactions.created_at) = calendar.datefield)
WHERE
(
calendar.datefield BETWEEN
(
SELECT Min(Date(created_at))
FROM transactions
)
AND
(
SELECT Max(Date(created_at))
FROM transactions
)
)
答案 0 :(得分:0)
SELECT calendar.datefield AS DATE,
Ifnull(Sum(transactions.deposit_amount),
0) AS total_deposits,
type
FROM
transactions
RIGHT JOIN
calendar
ON (
Date(transactions.created_at) = calendar.datefield
)
WHERE
(
calendar.datefield BETWEEN (SELECT
Min(Date(created_at))
FROM
transactions) AND (
SELECT
Max(Date(created_at ))
FROM
transactions
)
)
AND type = 'Deposit'
GROUP BY
date