คือผมแยกเป็นหมวดครับตามความเข้าใจไม่รู้ถูกต้องตามหลักไหม กำหนดเป็นแบบ text ทั้งหมดครับ
table A
-A1
-A2
-A3-A25
table B
-B1
-B2
-B3-B30
table C
-C1
-C2
-C3-C50
Select date_sale,
Sum(if(prod_id='aa',amount,0)) as aa,
Sum(if(prod_id='bb',amount,0)) as bb
From tablename
Where date_sale between startdate and lastdate
Group by date_sale
Select s.date_sale,
Sum(if(left(s.prod_id,2)='aa', b.amount,0)) as aa_in,
Sum(if(left(s.prod_id,2)='aa', s.amount,0)) as aa_out,
Sum(if(left(s.prod_id,2)='bb', b.amount,0)) as bb_in,
Sum(if(left(s.prod_id,2)='bb', s.amount,0)) as bb_out,
Sum(if(left(s.prod_id,2)='cc', b.amount,0)) as cc_in,
Sum(if(left(s.prod_id,2)='cc', s.amount,0)) as cc_out
From table_prod p
Left join sale s on p.prod_id=s.prod_id and s.date_sale between startdate and lastdate
Left join buy b on p.prod_id=b.prod_id and b.date_buy between startdate and lastdate
Group by date_sale
พี่ครับตอนนี้ผม Sum ออกมาแล้วได้แล้วเสร็จพอได้ค่า Sum แล้วผมจะเอามา บวก คูณ หาร ยังไงครับ
แบบนี้ครับ ISSUED หาร (RECEIRE บวก ISSUED) คูณ 100 = ผลรวม
Code
<?php
$result1 = mysql_query("SELECT sum(RECEIRE) FROM customer where wrench in ('RET14I','RET15','RET16','RET17','RET18','RET19','RET20','RET21','RET22','RET23','RET24','RET25','RET26','RET27','RET28','RET29','RET30')
and DATE( SAVE ) = CURDATE( ) ") or die(mysql_error());
while ($rows1 = mysql_fetch_array($result1)) {
?>
$result1 = mysql_query("SELECT SUM(ISSUED) FROM customer where wrench in ('RIT01','RIT02','RIT03','RIT04','RIT05','RIT06','RIT07','RIT08','RIT09','RIT10','RIT11','RIT12','RIT13','RIT14','RIT15','RIT16','RIT17','RIT18','RIT19','RIT20','RIT21','RIT22')
and DATE( SAVE ) = CURDATE( ) ") or die(mysql_error());
while ($rows1 = mysql_fetch_array($result1)) {
$result1 = mysql_query("SELECT SUM(TOTAL) FROM customer where wrench in ('RAD01','RAD02','RAD03','RAD04','RAD05','RAD06','RAD07','RAD08','RAD09','RAD10','RAD11','RAD12')
and DATE( SAVE ) = CURDATE( ) ") or die(mysql_error());
while ($rows1 = mysql_fetch_array($result1)) {