[英]MySQL force query to return NULL
I have the following: 我有以下几点:
SELECT q25, COUNT( q25 ) AS count, AVG (q1) AS q1
FROM tresults WHERE id = 'Yes' AND date = 'MARCH2010' AND q25 = '1'
GROUP BY q25
At the moment, the query returns MySQL returned an empty result set (ie zero rows).
此刻,查询返回MySQL returned an empty result set (ie zero rows).
which is correct - is it possible to get it to return NULL
instead? 哪个正确-是否有可能使它返回NULL
?
OR 要么
Is there a way of dealing with this after the event in PHP, such as: 在PHP中发生事件之后,是否有一种处理方法,例如:
$resultprev = mysql_query($queryprev);
if($resultprev == ''){
// do something
}
use mysql_num_rows : 使用mysql_num_rows :
$resultprev = mysql_query($queryprev);
$num_rows = mysql_num_rows($resultprev);
if($num_rows == 0){
// 0 results !
}
or you could union a null row : 或者您可以合并一个空行:
SELECT q25, COUNT( q25 ) AS count, AVG (q1) AS q1
FROM tresults WHERE id = 'Yes' AND date = 'MARCH2010' AND q25 = '1'
GROUP BY q25
UNION
SELECT null, null as count, null as q1
try this 尝试这个
if(mysql_affected_rows($res)) {
//your stuff
}
or in sql 或在sql中
SELECT (
SELECT q25, COUNT( q25 ) AS count, AVG (q1) AS q1
FROM tresults WHERE id = 'Yes' AND date = 'MARCH2010' AND q25 = '1'
GROUP BY q25
UNION
SELECT null, null, null
) AS x
LIMIT 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.