Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > จะหาผลรวม หลังจาก Sum ใน SQL แล้วได้ยังไงครับ หลังจากที่ หาผลรวมจากการ คิวรี่แล้ว ต้องการนำผมรวมที่ได้จากการคิวรี่ มา รวมกันอีกที ยังไงครับ



 

จะหาผลรวม หลังจาก Sum ใน SQL แล้วได้ยังไงครับ หลังจากที่ หาผลรวมจากการ คิวรี่แล้ว ต้องการนำผมรวมที่ได้จากการคิวรี่ มา รวมกันอีกที ยังไงครับ

 



Topic : 038227



โพสกระทู้ ( 91 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook



<?php
Conn2DB();

mysql_query("set NAMES tis620");
mysql_query("set character_set_results=tis620");
mysql_query("set character_set_connection=tis620");
mysql_query("set character_set_client=tis620");

$stryear = date("Y");

$strSQL = "SELECT * ";
$strSQL .= ",SUM(case when month(rdate)='1' then volume end) AS q1";
$strSQL .= ",SUM(case when month(rdate)='1' then amount end) AS r1";
$strSQL .= ",SUM(case when month(rdate)='2' then volume end) AS q2";
$strSQL .= ",SUM(case when month(rdate)='2' then amount end) AS r2";
$strSQL .= ",SUM(case when month(rdate)='3' then volume end) AS q3";
$strSQL .= ",SUM(case when month(rdate)='3' then amount end) AS r3";
$strSQL .= ",SUM(case when month(rdate)='4' then volume end) AS q4";
$strSQL .= ",SUM(case when month(rdate)='4' then amount end) AS r4";
$strSQL .= ",SUM(case when month(rdate)='5' then volume end) AS q5";
$strSQL .= ",SUM(case when month(rdate)='5' then amount end) AS r5";
$strSQL .= ",SUM(case when month(rdate)='6' then volume end) AS q6";
$strSQL .= ",SUM(case when month(rdate)='6' then amount end) AS r6";
$strSQL .= ",SUM(case when month(rdate)='7' then volume end) AS q7";
$strSQL .= ",SUM(case when month(rdate)='7' then amount end) AS r7";
$strSQL .= ",SUM(case when month(rdate)='8' then volume end) AS q8";
$strSQL .= ",SUM(case when month(rdate)='8' then amount end) AS r8";
$strSQL .= ",SUM(case when month(rdate)='9' then volume end) AS q9";
$strSQL .= ",SUM(case when month(rdate)='9' then amount end) AS r9";
$strSQL .= ",SUM(case when month(rdate)='10' then volume end) AS q10";
$strSQL .= ",SUM(case when month(rdate)='10' then amount end) AS r10";
$strSQL .= ",SUM(case when month(rdate)='11' then volume end) AS q11";
$strSQL .= ",SUM(case when month(rdate)='11' then amount end) AS r11";
$strSQL .= ",SUM(case when month(rdate)='12' then volume end) AS q12";
$strSQL .= ",SUM(case when month(rdate)='12' then amount end) AS r12 ";
$strSQL .= "FROM invoicedetail INNER JOIN invoiceno ON invoiceno.invoiceno = invoicedetail.invoiceno ";
$strSQL .= "INNER JOIN product ON product.productid = invoicedetail.productid ";
$strSQL .= "WHERE year(rdate) = '$stryear' ";
$strSQL .= "GROUP BY invoicedetail.invdetailid ";
$strSQL .= "ORDER BY invoiceno.customerid DESC ";

$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="3275" border="1" cellpadding="1" cellspacing="0" bordercolordark="#CCCCCC" bordercolorlight="#CCCCCC" class="style01">
<tr bgcolor="#919191">
<th width="100" rowspan="2"> <div align="center">CustomerID </div></th>
<th width="185" rowspan="2"> <div align="center">CustomerName </div></th>
<th width="175" rowspan="2"><div align="center">ProductID </div></th>
<th width="301" rowspan="2"><div align="center">Description</div></th>
<th colspan="2"> <div align="center">January</div> </div></th>
<th colspan="2"> <div align="center">February </div></th>
<th colspan="2"> <div align="center">March </div></th>
<th colspan="2"> <div align="center">April</div></th>
<th colspan="2"> <div align="center">May </div></th>
<th colspan="2"> <div align="center">June </div></th>
<th colspan="2"> <div align="center">July</div></th>
<th colspan="2"> <div align="center">August</div></th>
<th colspan="2"> <div align="center">September </div></th>
<th colspan="2"> <div align="center">October</div></th>
<th colspan="2"> <div align="center">November</div></th>
<th colspan="2"> <div align="center">December</div></th>
</tr>
<tr align="center" class="style02" bgcolor="<?=$bg;?>">
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
<td width="100" bgcolor="#FAFDBB">Quantity</td>
<td width="100" bgcolor="#FAFDBB">Revenue</td>
</tr>
<?php

$i=0;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
if($i%3==0)
{
$bg = "#E9E9E9";
}
else
{
$bg = "#FFFFFF";
}

?>
<tr align="center" class="style02" bgcolor="<?=$bg;?>">
<td><?=$objResult["customerid"];?></td>
<td><?=$objResult["customername"];?></td>
<td><?=$objResult["productid"];?>&nbsp;</td>
<td><?=$objResult["description"];?></td>
<td><?=number_format($objResult["q1"],2);?></td>
<td><?=number_format($objResult["r1"],2);?></td>
<td><?=number_format($objResult["q2"],2);?></td>
<td><?=number_format($objResult["r2"],2);?></td>
<td><?=number_format($objResult["q3"],2);?></td>
<td><?=number_format($objResult["r3"],2);?></td>
<td><?=number_format($objResult["q4"],2);?></td>
<td><?=number_format($objResult["r4"],2);?></td>
<td><?=number_format($objResult["q5"],2);?></td>
<td><?=number_format($objResult["r5"],2);?></td>
<td><?=number_format($objResult["q6"],2);?></td>
<td><?=number_format($objResult["r6"],2);?></td>
<td><?=number_format($objResult["q7"],2);?></td>
<td><?=number_format($objResult["r7"],2);?></td>
<td><?=number_format($objResult["q8"],2);?></td>
<td><?=number_format($objResult["r8"],2);?></td>
<td><?=number_format($objResult["q9"],2);?></td>
<td><?=number_format($objResult["r9"],2);?></td>
<td><?=number_format($objResult["q10"],2);?></td>
<td><?=number_format($objResult["r10"],2);?></td>
<td><?=number_format($objResult["q11"],2);?></td>
<td><?=number_format($objResult["r11"],2);?></td>
<td><?=number_format($objResult["q12"],2);?></td>
<td><?=number_format($objResult["r12"],2);?></td>
</tr>
<?php
}
?>
<tr align="center" class="style02" bgcolor="<?=$bg;?>">
<td colspan="4" align="right"><strong>Total&nbsp;&nbsp;</strong></td>
<td><?php echo number_format("$allq1",2);?></td>
<td><?=number_format($objResult["allr1"],2);?></td>
<td><?=number_format($objResult["allq2"],2);?></td>
<td><?=number_format($objResult["allr2"],2);?></td>
<td><?=number_format($objResult["allq3"],2);?></td>
<td><?=number_format($objResult["allr3"],2);?></td>
<td><?=number_format($objResult["allq4"],2);?></td>
<td><?=number_format($objResult["allr4"],2);?></td>
<td><?=number_format($objResult["allq5"],2);?></td>
<td><?=number_format($objResult["allr5"],2);?></td>
<td><?=number_format($objResult["allq6"],2);?></td>
<td><?=number_format($objResult["allr6"],2);?></td>
<td><?=number_format($objResult["allq7"],2);?></td>
<td><?=number_format($objResult["allr7"],2);?></td>
<td><?=number_format($objResult["allq8"],2);?></td>
<td><?=number_format($objResult["allr8"],2);?></td>
<td><?=number_format($objResult["allq9"],2);?></td>
<td><?=number_format($objResult["allr9"],2);?></td>
<td><?=number_format($objResult["allq10"],2);?></td>
<td><?=number_format($objResult["allr10"],2);?></td>
<td><?=number_format($objResult["allq11"],2);?></td>
<td><?=number_format($objResult["allr11"],2);?></td>
<td><?=number_format($objResult["allq12"],2);?></td>
<td><?=number_format($objResult["allr12"],2);?></td>
</tr>
</table>


หลังจากที่ หาผลรวมจากการ คิวรี่แล้ว ต้องการนำผมรวมที่ได้จากการคิวรี่ มา รวมกันอีกที ยังไงครับ
คือได้ q1 แล้ว จะเอาผลรวมของ q1 มาเก็บไว้ใน allq1 ครับ


ขอบคุณครับ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-02-03 09:09:30 By : mac1626 View : 1500 Reply : 10
 

 

No. 1



โพสกระทู้ ( 91 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook

ไม่มีคนตอบ ฮือๆๆๆ






Date : 2010-02-03 15:21:17 By : mac1626
 


 

No. 2



โพสกระทู้ ( 95 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

array_sum($objResult["q1"]);

จะช่วยได้ไหมครับ?
Date : 2010-02-03 15:25:42 By : p_latplee
 

 

No. 3



โพสกระทู้ ( 91 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook

มัน error อ่ะครับ

ขอบคุณทุกคำตอบครับ
Date : 2010-02-03 16:53:01 By : mac1626
 


 

No. 4

Guest


ช่วยดู ทีครับ

ต้องเอาไปวางไว้ตรงไหนครับ
Date : 2010-02-04 08:48:14 By : mac1626
 


 

No. 5



โพสกระทู้ ( 91 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook

เน่า ครับ ลบที เซง
Date : 2010-02-04 13:40:43 By : mac1626
 


 

No. 6



โพสกระทู้ ( 91 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook

""" help me please
Date : 2010-02-05 09:09:25 By : mac1626
 


 

No. 7



โพสกระทู้ ( 3 )
บทความ ( 0 )



สถานะออฟไลน์


ลองทำดูแล้วยังติดอยู่
Date : 2010-02-05 09:18:16 By : mee3774
 


 

No. 8



โพสกระทู้ ( 91 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook

ยังไงก็ ขอบคุณครับ

ผมก็ลองดู แล้ว พลิกแพลง ดูแล้ว มันก็ได้ผลไม่ตรงตามที่ต้องการ อ่ะ ครับ

เลย จนปัญญาจริงๆ
Date : 2010-02-05 11:19:30 By : mac1626
 


 

No. 9

Guest


ในหารวนลูปแต่ละครั้งเก็บเป็นตัวแปรได้มั๊ยครับบ แล้วค่อยเอามาใช้อีกที
Date : 2010-02-05 12:43:38 By : ochitae
 


 

No. 10

Guest


เพิ่ม ไปใน sql ตรงๆเลยได้ไหม
$strSQL .= ",SUM(case when year(rdate)=''$stryear' then amount end) AS yr12 ";
Date : 2010-02-05 15:56:52 By : pheak
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : จะหาผลรวม หลังจาก Sum ใน SQL แล้วได้ยังไงครับ หลังจากที่ หาผลรวมจากการ คิวรี่แล้ว ต้องการนำผมรวมที่ได้จากการคิวรี่ มา รวมกันอีกที ยังไงครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่