<?
$strSQL = "select count(service) AS countservice from detail GROUP BY service";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mssql_fetch_array($objQuery))
{
echo $objResult["countservice"];
echo "<br>";
}
?>
2.ถ้าผมจะเลือก COUNT ข้อมูลบางตัวในฟิวส์ service โดยนับเฉพาะที่มีรหัสฟิวส์ bg เหมือนกันจะเขียนอย่างไรครับ
SELECT service,COUNT(service) AS countservice FROM detail GROUP BY service ORDER BY countservice DESC
ข้อ2อ่านแล้วยังงงๆ แบบนี้รึป่าว นับข้อมูลที่ซ้ำกัน
SELECT service,COUNT(service) AS countservice FROM detail GROUP BY service HAVING countservice > 1 ORDER BY countservice DESC
$strSQL="select bg,service,COUNT(service) AS countservice from detail WHERE bg = 55 GROUP BY service ORDER BY countservice DESC"; ERROR ครับ
Warning: mssql_query() [function.mssql-query]: message: Column 'detail.bg' 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_business.php on line 226
Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\1799\report_business.php on line 226
Error Query [select bg,service,COUNT(service) AS countservice from detail WHERE bg = 55 GROUP BY service ORDER BY countservice DESC]
1. มีฟิวส์ bg ครับ
2. error อยู่ครับ
Warning: mssql_query() [function.mssql-query]: message: Column 'detail.bg' 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_business.php on line 228
Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\1799\report_business.php on line 228
Error Query [select bg,service,COUNT(service) from detail WHERE bg = '55' GROUP BY service ORDER BY service DESC]
Warning: mssql_query() [function.mssql-query]: message: Column 'detail.bg' 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_business.php on line 228
Warning: mssql_query() [function.mssql-query]: Query failed in C:\AppServ\www\1799\report_business.php on line 228
Error Query [select bg,service,COUNT(service) from detail WHERE bg = 55 GROUP BY service ORDER BY service DESC]