试题选项表t_ems_item_option中有item_id试题id,option_id选项id,is_correct是否正确答案
例如   item_id    option_id    is_correct试题1          a            f
试题1          b            f
试题1          c           f
试题1          d         t试题2         a          f
试题2          b           f
试题2          c           f
试题2         d          f
求找到试题2

解决方案 »

  1.   

    两个sum 比较。相等,就是没有正确的。
    select st from(
    select count(1) n1 ,st from T group by st) a
    join 
    (select count(1) n2,st,iscorect from T group by st,iscorect)
    b
    on a.st=b.st
    where a.n1=b.n2
      

  2.   

    select  item_id from  t_ems_item_option where  is_correct=false
      

  3.   

    SELECT item_id FROM t_ems_item_option where item_id not in (select item_id FROM t_ems_item_option where is_correct='t' ) group by item_id;
      

  4.   

    select item_id from t_ems_item_option where is_correct='f' group by item_id having count(item_id)=4
      

  5.   


    SELECT
     item_id
    FROM t_ems_item_option
    GROUP BY
     item_id
    HAVING
     COUNT(item_id) = COUNT(IF(is_correct = 'f', item_id, NULL))
      

  6.   


    SELECT 
      item_id
    FROM
      t_ems_item_option
    GROUP BY
      item_id
    HAVING
      SUM(CASE WHEN is_correct = 't' THEN 1 ELSE 0 END) = 0