select SUM(number),name_item,item.barcode_item from s_stock LEFT JOIN item ON s_stock.barcode_item = item.barcode_item order by s_stock.barcode_item ASC group by name_item
<?php
mysql_connect('localhost', 'root', '') or die (mysql_error());
mysql_select_db('yourdatabases');
$sql = " SELECT SUM(number),name_item,item.barcode_item FROM s_stock ";
$sql.= " LEFT JOIN item ON (s_stock.barcode_item = item.barcode_item) ";
$sql.= " ORDER BY s_stock.barcode_item ASC GROUP BY name_item ";
$qr = mysql_query($sql) or die (mysql_error());
if($qr){
while($fetch = mysql_fetch_assoc($qr)){
echo $fetch['name_item'];
echo '<br />';
echo $fetch['barcode_item'];
}
}else{
echo $qr;
}
?>
ลองนำไปรันดูนะครับ
ประวัติการแก้ไข 2012-12-25 09:30:29
Date :
2012-12-25 09:27:45
By :
popnakub
No. 2
Guest
select name_item,item.barcode_item,SUM(number) from s_stock LEFT JOIN item ON s_stock.barcode_item = item.barcode_item group by item.barcode_item order by barcode_item DESC