|
|
|
ขอถามเกี่ยวกับการ Min Max SQL PHP แบบหลายคอลัมน์ หน่อยค่ะ |
|
|
|
|
|
|
|
หนูจะหา MIN กับ MAX โดยใช้ While หารายการข้อมูล NAME ทั้งหมด มาเพื่อหาค่า MIN กับ MAX
จากโค๊ดด้านล่างจะสามารถดึงข้อมูลได้แค่ NAME เดียวคือรายการสุดท้าย
หนูลองเช็ค Array ก็มาเพียง 1 รายการจิงๆค่ะ
ช่วยหน่อยนะค่ะ งงๆ มาหลายวันแล้วค่ะ
Code (PHP)
<?
$strSQLmin = "SELECT * from Test where NAME='$_GET[id]' ";
$objQuerymin = mssql_query($strSQLmin) or die ("Error Query [".$strSQLmin."]");
while($min_BEF = mssql_fetch_array($objQuerymin))
{
$tmp_min = array($min_BEF["B_E11"],$min_BEF["B_F11"],$min_BEF["B_E12"], $min_BEF["B_F12"],$min_BEF["B_E13"],$min_BEF["B_F13"], $min_BEF["B_E14"],$min_BEF["B_F14"],$min_BEF["B_E15"], $min_BEF["B_F15"],$min_BEF["B_E16"],$min_BEF["B_F16"] ,$min_BEF["B_E17"],$min_BEF["B_F17"],$min_BEF["B_E18"] ,$min_BEF["B_F18"],$min_BEF["B_E21"],$min_BEF["B_F21"] ,$min_BEF["B_E22"],$min_BEF["B_F22"],$min_BEF["B_E23"] ,$min_BEF["B_F23"],$min_BEF["B_E24"],$min_BEF["B_F24"] ,$min_BEF["B_E25"],$min_BEF["B_F25"],$min_BEF["B_E26"] ,$min_BEF["B_F26"],$min_BEF["B_E27"],$min_BEF["B_F27"],$min_BEF["B_E28"]);
}
$array_min = min($tmp_min);
echo number_format($array_min , 2);
?>
Array
Code
Array ( [0] => 1.89 [1] => 2.31 [2] => 2.11 [3] => 1.69 [4] => 2.38 [5] => 2.4 [6] => 2.3 [7] => 2.01 [8] => 1.69 [9] => 2.31 [10] => 2.11 [11] => 2 [12] => 2.51 [13] => 1.92 [14] => 2.31 [15] => 2.4 [16] => 2.59 [17] => 1.96 [18] => 2.97 [19] => 2 [20] => 2.98 [21] => 2.36 [22] => 3.01 [23] => 1.92 [24] => 1.69 [25] => 2.51 [26] => 2.31 [27] => 2 [28] => 1.51 [29] => 1.92 [30] => 2.2 [31] => 2.26 )
ฐานข้อมูล
Code (SQL)
/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP 100 [ID]
[ID]
,[NAME]
,[B_E11]
,[B_F11]
,[B_E12]
,[B_F12]
,[B_E13]
,[B_F13]
,[B_E14]
,[B_F14]
,[B_E15]
,[B_F15]
,[B_E16]
,[B_F16]
,[B_E17]
,[B_F17]
,[B_E18]
,[B_F18]
,[B_E21]
,[B_F21]
,[B_E22]
,[B_F22]
,[B_E23]
,[B_F23]
,[B_E24]
,[B_F24]
,[B_E25]
,[B_F25]
,[B_E26]
,[B_F26]
,[B_E27]
,[B_F27]
,[B_E28]
,[B_F28]
FROM [SPSTRENGTH].[dbo].[Test]
Tag : PHP, MySQL, Ms SQL Server 2008, Ms SQL Server 2012, CakePHP
|
|
|
|
|
|
Date :
2013-07-25 16:40:51 |
By :
loomoo |
View :
756 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองใช้พวก Function ดูยังครับ
SQL MAX
SQL MIN
|
|
|
|
|
Date :
2013-07-25 18:16:14 |
By :
Krungsri |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|