【问题标题】:Incorrect parameter when using IsNull in MySQL在 MySQL 中使用 IsNull 时参数不正确
【发布时间】:2010-05-06 23:23:20
【问题描述】:

我一直在尝试使用IsNull() 函数来确保字段存在值。

SELECT crawled.id,
       IsNull(sranking.score,0) as Score,
       crawled.url,
       crawled.title,
       crawled.blurb
FROM crawled
    LEFT JOIN sranking ON crawled.id = sranking.sid
WHERE crawled.body LIKE '%".$term."%'
ORDER BY Score DESC LIMIT " . $start . "," . $c

但我收到错误消息:

调用本机函数“IsNull”时的参数计数不正确

有人有什么想法吗?我对 MySQL 很陌生。

【问题讨论】:

    标签: mysql join


    【解决方案1】:

    ISNULL 测试传递的表达式是否为 NULL。您需要的是 IFNULL 或 COALESCE,正如 xyld 所提到的。

    SELECT crawled.id, IFNULL(sranking.score, 0) as Score, ...
    

    【讨论】:

      【解决方案2】:

      您可以考虑使用coalescehttp://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_coalesce

      它返回第一个非空值。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-16
        • 2012-05-14
        • 2017-10-18
        • 1970-01-01
        • 2023-03-29
        相关资源
        最近更新 更多