SQL从列转换为行

时间:2018-07-19 02:38:06

标签: mysql

我有这样的查询,结果是这样的:

Current Result

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

有可能转变成这个吗? Expected Result

0 个答案:

没有答案