我需要获得所有期间和当月的付款金额。有两个表:类别和交易。
交易:
id int(11)
category varchar(32)
dttm_added datetime
minus float
minus_currency varchar(32)
类别:
id int(11)
key varchar(32)
name varchar(50)
type varchar(1)
这是我的查询:
select `key`, `id`, `name`, minus_month,month_cur
from `categories` as ct
left join (
select `category` as tr_ct_m, date_format(`dttm_trans`, '%Y%m') as dat, sum(`minus`) as minus_month, `minus_currency` as month_cur from `transactions` where dat = date_format(now(), '%Y%m')
) as tr_m on tr_m.tr_ct_m = ct.key
where `type` = '-'
我需要在加入之前检查 select 中的子句,因为在减月的总和之后,所有日期都变为 Null。帮助请