select UserID,color,SUM(number) from `order_detail` group by color and group by UserID
ตอนนี้ผมใช้แบบนี้อยู่
$sql1="select * from `agent` order by `Name` DESC ";
$qr1 =@mysql_db_query($dbname,$sql1) or die("error $sql1");
$row1 =@mysql_num_rows($qr1);
$i=0;
while ($i<$row1){
$rs1=mysql_fetch_array($qr1);
$UserID1 = $rs1[UserID];
$Name1 = $rs1[Name];
$sql="select date_order_detail,order_detail.id_brand,name_brand,SUM(number),SUM(sum_price) from `order_detail` LEFT JOIN brand ON `order_detail`.id_brand = brand.id_brand where UserID = '$UserID1' and ".date_order_detail." like '%".$date1."%' group by `order_detail`.id_brand " ;
}
$Qtotal = mysql_query($sql);
$qr =@mysql_db_query($dbname,$sql) or die("error $sql");
$row =@mysql_num_rows($qr);
while($result = mysql_fetch_array($qr)){
$sumnumber = $result['SUM(number)'];
$sumprice = $result['SUM(sum_price)'];
}