1

我正在尝试运行此 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 的值

4

1 回答 1

3

在这种情况下使用HAVING代替。WHERE

$sql="SELECT LEAST(".implode(',',$column_list).") as num FROM callplandata HAVING num != 0 ";

有什么区别?WHEREGROUP BY操作之前应用,LEAST还必须在返回之前对结果进行分组(因此在计算结果之前调用 WHERE 子句),HAVING在之后应用(并且可以过滤诸如MIN, MAX, LEAST等之类的聚合)。

于 2013-08-21T07:30:00.077 回答