SELECT `Name and Post Code` ,
SUM( IF( `Month` = '2016-09', `Qty` , '' ) ) AS Sep,
SUM( IF( `Month` = '2016-10', `Qty` , '' ) ) AS Oct,
SUM( IF( `Month` = '2016-11', `Qty` , '' ) ) AS Nov,
SUM( IF( `Month` = '2017-01', `Qty` , '' ) ) AS Jan,
SUM( IF( `Month` = '2017-02', `Qty` , '' ) ) AS Feb
FROM `Main`
WHERE `Corporate Group` = 'Brogans'
GROUP BY `Name and Post Code`
WITH ROLLUP;
我在MySQL中执行了上述代码,以便在数据库中提供各种客户的销售数据,如下所示:
我每月总计。 (垂直/列总数)。我想得到每个客户的总数。 (水平总计)
表(Main
)结构:
ID - int(10)
Corporate Group - varchar (25)
Account Number - varchar (25)
Name and Post Code - varchar (200)
Post Code - varchar(50)
Supplier Code - varchar (100)
Description - varchar (200)
Qty - varchar (50)
Month - varchar (50)
Code & Description - varchar (200)
非常感谢