到目前为止,我有这段代码,它为我提供了给定月份每种产品的小计。
<?php
include("dbaseconn.php");
$query = "SELECT product, SUM(qty) FROM sh_orders GROUP BY product";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "<table width='1050'>" ;
echo "<td width='400'>";
echo "". $row['product']. " ";
echo "</td>";
echo "<td>";
echo "". $row['SUM(qty)']. "" ;
echo "</td>";
echo "<br />";
}
?>
表结构
CREATE TABLE IF NOT EXISTS `sh_orders` (
`building` varchar(50) NOT NULL,
`qty` varchar(5) NOT NULL,
`product` varchar(50) NOT NULL,
`order_id` bigint(5) NOT NULL AUTO_INCREMENT,
`unik` varchar(50) NOT NULL,
`order_date` varchar(25) NOT NULL,
`co_id` varchar(20) NOT NULL,
UNIQUE KEY `unik` (`unik`),
UNIQUE KEY `id` (`order_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
我想显示过去 12 个月的销售额 - SUM (qty) 为我执行此操作,但我需要分别查看每个月的每种产品及其当月的总销售额。我需要在一张表中显示每个月的每种产品和该月的总计
EXPECTED RESULT
Month: January 2012 Feb 2012 Marc 2012
Product1: 124 105 76
Product2: 34 23 56
Product3: 12 5 6
我是新手,所以如果我问一百万个问题,请耐心等待。