我有这样的查询,结果是这样的:
SELECT
DATE_FORMAT(data2.date1, '%b %y') as date,
custlist1.Custcat,
sum(data2.quantity/1000) AS UnitMT
FROM data2
INNER JOIN custlist1 on data2.customeracc = custlist1.Customeraccount
WHERE date1 >= '2018-06-22' - INTERVAL 12 MONTH
AND
data2.unit = 'KG'
AND
data2.customeracc not in (select Customeraccount from custlist WHERE Custcat = 'bcsb')
AND
data2.region in ('central','eastern','southern','northern')
AND
custlist1.Custcat not in ('SABARICE','SAZARICE','OTHERS','TONG SENG HUAT RICE','LIANSIN-TRADING')
AND
custlist1.Custcat = 'oel'
GROUP BY month(date1),custlist1.Custcat