select ifnull(question_id,0)
from t_test_paper_question_s a left join t_test_question b on(a.question_id = b.id)
where paper_id = 83
and question_no_b=4          
and question_no_s = 5
and difficult='ED010'
数据为null的为什么查出来后还是null,为什么不是-1呢?

解决方案 »

  1.   

    select ifnull(question_id,-1)没问题。你查一下你的条件和数据吧。为什么还有null
      

  2.   

    条件没错,换成有数据的那条能查出来,换成没数据的那条就成null了,不知道为什么啊
      

  3.   

    select ifnull(question_id,0)
    from t_test_paper_question_s 那这样会不会有问题。
      

  4.   

    这样查  question_id都有值
      

  5.   

    问了下经理总算搞清楚了,其实是我没理解好ifnull,那个sql语句查询出来的是没记录,而ifnull是指有记录时,如果为null就变为指定的值,感谢回复的人,散分了