<?
include("connect.inc");
$strSQL="SELECT service,COUNT(bg) AS countservice FROM detail WHERE bg=55 GROUP BY service ORDER BY service";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mssql_fetch_array($objQuery))
{
echo "<font color=red>".$objResult["service"]." </font>";
echo "<font color=red>".$objResult["countservice"]." </font>";
echo "<br>";
}
?>
LEFT JOIN ละครับผลคือ 149 ผลิตภัณฑ์น้ำ 55
150 ผลิตภัณฑ์เครื่องดื่มสำเร็จรูป 55
151 ผลิตภัณฑ์เครื่องดื่มผสม 55 แต่พอ COUNT error เลยครับ จะให้มันนับว่ามีข้อมูลทั้งหมดเท่าไหร่ของ bg=55 ที่ีมีในตาราง detail Warning: mssql_query() [function.mssql-query]: message: Column 'service.ser_no' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. (severity 16) in C:\AppServ\www\1799\report_business1.php on line 17
Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\1799\report_business1.php on line 17
Error Query [SELECT service.*,detail.*,COUNT(detail.bg) AS countname FROM service LEFT JOIN detail ON service.ser_no = detail.id WHERE service.bg_no=55] Code (PHP)
<?
include("connect.inc");
$strSQL="SELECT service.*,detail.*,COUNT(detail.bg) AS countname FROM service LEFT JOIN detail ON service.ser_no = detail.id WHERE service.bg_no=55";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mssql_fetch_array($objQuery))
{
echo "<font color=red>".$objResult["ser_no"]." </font>";
echo "<font color=red>".$objResult["ser_name"]." </font>";
echo "<font color=red>".$objResult["bg_no"]." </font>";
echo "<font color=red>".$objResult["countname"]." </font>";
echo "<br>";
}
?>
ทำไมผม COUNT ไม่ได้ครับ
SELECT service.*,detail.*,COUNT(detail.bg) AS countname FROM service LEFT JOIN detail ON service.ser_no = detail.id WHERE service.bg_no=55
Warning: mssql_query() [function.mssql-query]: message: Column 'detail.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. (severity 16) in C:\AppServ\www\1799\report_business1.php on line 17
Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\1799\report_business1.php on line 17
Error Query [SELECT detail.*,service.*,COUNT(detail.bg) AS countname FROM service LEFT JOIN detail ON service.ser_no = detail.id WHERE service.bg_no=55 GROUP BY detail]
Code (PHP)
$strSQL="SELECT detail.*,service.*,COUNT(detail.bg) AS countname FROM service LEFT JOIN detail ON service.ser_no = detail.id WHERE service.bg_no=55 GROUP BY detail
$strSQL="SELECT detail.*,service.*,COUNT(detail.bg) AS countname FROM service LEFT JOIN detail ON service.ser_no = detail.id WHERE service.bg_no=55 GROUP BY detail.*,service.*";
$strSQL="SELECT detail.service,detail.bg,service.ser_no,service.ser_name,service.bg_no,COUNT(detail.bg) AS countname FROM service LEFT JOIN detail ON service.ser_no = detail.id WHERE service.bg_no=55 GROUP BY detail.id,detail.service,detail.bg,service.ser_no,service.ser_name,service.bg_no";