我正在尝试运行此SQL:
$sql="SELECT LEAST(".implode(',',$column_list).") as num FROM callplandata WHERE num IS NOT 0 ";
错误:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1
我也试过
$sql="SELECT LEAST(".implode(',',$column_list).") as num FROM callplandata WHERE num IS NOT NULL ";
错误:Unknown column 'num' in 'where clause'
但是每个人都会遇到上述错误。
我怎么能绕过这个 - 我试图显示非0的值
答案 0 :(得分:3)
在这种情况下,请使用HAVING
代替WHERE
。
$sql="SELECT LEAST(".implode(',',$column_list).") as num FROM callplandata HAVING num != 0 ";
差异是什么?在WHERE
操作之前应用GROUP BY
,LEAST
也必须在返回之前对结果进行分组(因此在计算结果之前调用WHERE子句),HAVING
已应用之后(并且可以过滤MIN, MAX, LEAST
等聚合。)