求写一个sql,查询没有正确答案的试题id

xuebo_xu 2018-07-02 10:43:42
试题选项表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
...全文
350 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yc_39 2018-10-18
  • 打赏
  • 举报
回复

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
HipPop223 2018-07-03
  • 打赏
  • 举报
回复

SELECT
item_id
FROM t_ems_item_option
GROUP BY
item_id
HAVING
COUNT(item_id) = COUNT(IF(is_correct = 'f', item_id, NULL))
Rickshawboylu 2018-07-02
  • 打赏
  • 举报
回复
select item_id from t_ems_item_option where is_correct=false
  • 打赏
  • 举报
回复
两个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
楓VS痕 2018-07-02
  • 打赏
  • 举报
回复
select item_id from t_ems_item_option where is_correct='f' group by item_id having count(item_id)=4
熊心壮智 2018-07-02
  • 打赏
  • 举报
回复
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;

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧