代码之家  ›  专栏  ›  技术社区  ›  Roger

不像不在MySQL中使用Rails

  •  0
  • Roger  · 技术社区  · 16 年前
    >> Comment.count
      SQL (0.3ms)   SELECT count(*) AS count_all FROM `comments` 
    => 451
    >> Comment.count(:conditions => ["author_website not like ?",'aaaa'])
      SQL (1.4ms)   SELECT count(*) AS count_all FROM `comments` WHERE (author_website not like 'aaaa') 
    => 203
    >> Comment.count(:conditions => ["author_website like ?",'aaaa'])
      SQL (1.2ms)   SELECT count(*) AS count_all FROM `comments` WHERE (author_website like 'aaaa') 
    => 0
    >> 
    

    我以为不喜欢的人数是451。

    我正在使用MySQL和RubyonRails。

    2 回复  |  直到 16 年前
        1
  •  2
  •   Adam    16 年前

    author_网站是否为可空字段?

    如果248行有空值,这可能解释了这一点。

    你能改做这个吗?

    Comment.count(:conditions => ["not(author_website like ?)",'aaaa'])
    
        2
  •  1
  •   Mike Tunnicliffe    16 年前

    正如Troleskn在他的评论中暗示的那样,如果一个值为NULL,那么它既不象也不象任何特定的值。尝试:

    Comment.count(:conditions => ["author_website is null OR author_website not like ?", 'aaaa'])