include "conn.php";
$strSQL= "SELECT date , type , IF((type=YES)COUNT(type) AS t1) , IF((type=NO)COUNT(type) AS t2) , SUM(score) AS v2 , SUM(amount) AS a2 FROM daily WHERE location='$location' GROUP BY date , type ORDER BY date";
$objQuery = mssql_query($strSQL) or die ("Error Query [".$strSQL."]");
while($objResult = mssql_fetch_array($objQuery))
{
echo $objResult["date"] ;
echo "<br>";
echo $objResult["type"] ;
echo "<br>";
echo $objResult["t1"] ;
echo "<br>";
echo $objResult["t2"] ;
echo "<br>";
echo $objResult["location"] ;
echo "<br>";
echo $objResult["v2"] ;
echo "<br>";
echo $objResult["a2"] ;
echo "<br><br>";
}
Code
Warning: mssql_query(): message: Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection. (severity 14) in d:\appserv\www\.....
Warning: mssql_query(): Unable to connect to server: (null) in d:\appserv\www.....
Warning: mssql_query(): A link to the server could not be established in d:\appserv\www....
Error Query [SELECT date , type , IF((type=YES)COUNT(type) AS t1) , IF((type=NO)COUNT(type) AS t2) , SUM(score) AS v2 , SUM(amount) AS a2 FROM daily WHERE location='A' GROUP BY date , type ORDER BY date]
ถ้า select แบบไม่ใส่ IF และ where type ตรงๆ ไม่ error อ่ะค่ะ
เลยคิดว่าน่าเป็นที่ IF อ่ะค่ะ
Code (PHP)
include "conn.php";
$sql = "SELECT date , type , COUNT(type) AS t2 , SUM(score) AS v2 , SUM(amount) AS a2 FROM daily WHERE location='$location' and type='A' GROUP BY date , type ORDER BY date";
$sqlquery=mysql_db_query($dbname, $sql);
while($res = mysql_fetch_array($sqlquery))
{
echo $res['date'];
echo "<br>";
echo $res['type'];
echo "<br>";
echo $res['t2'];
echo "<br>";
echo $res['v2'];
echo "<br>";
echo $res['a2'];
echo "<br><br>";
}
SELECT
date , type ,
(select count(type) as Yes from daily as v1 where v1.date = v2.date and v1.location = v2.location and v1.type = 'YES') as Yes,
(select count(type) as No from daily as v1 where v1.date = v2.date and v1.location = v2.location and v1.type = 'NO') as No,
SUM(score) AS Score,
SUM(amount) AS Amount
FROM
daily as v2
WHERE location='$location'
GROUP BY date , type
ORDER BY date