add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE data1(
student int,
answer int
);
INSERT INTO data1(student, answer)
VALUES
(100, 1),
(100, 2),
(101, 1),
(101, 9),
(102, 1),
(102, 2),
(102, 2),
(103, 8),
(104, 2),
(104, 9);

Records: 10  Duplicates: 0  Warnings: 0
select student, if((sum(cnt)<>count(*)) or ((count(*)>1) and (max(answer)>7)), 'INVALID', 'Valid') as Result
from
(
select student, answer, count(*) as cnt
from data1
group by student, answer
) as sub
group by student
student Result
100 Valid
101 INVALID
102 INVALID
103 Valid
104 INVALID