試題選項表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
uj5u.com熱心網友回復:
兩個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
uj5u.com熱心網友回復:
select item_id from t_ems_item_option where is_correct=falseuj5u.com熱心網友回復:
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;uj5u.com熱心網友回復:
select item_id from t_ems_item_option where is_correct='f' group by item_id having count(item_id)=4uj5u.com熱心網友回復:
SELECT
item_id
FROM t_ems_item_option
GROUP BY
item_id
HAVING
COUNT(item_id) = COUNT(IF(is_correct = 'f', item_id, NULL))
uj5u.com熱心網友回復:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/79492.html
標籤:MySQL
