P
P
pgamesorg2021-04-11 16:53:08
SQL
pgamesorg, 2021-04-11 16:53:08

How to write a query to display classes in which only excellent students?

Display a list of classes with only excellent students

, let's say a table with 2 columns:

class and annual grade

, you need to display those classes in which there are only fives

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
BorLaze, 2021-04-11
@BorLaze

As an option:

select distinct class
from t
where class not in (select distinct class from t where score <> 5)

S
Slava Rozhnev, 2021-04-11
@rozhnev

For example like this:

select class
from students
group by class
having count(*)*5 = sum(rang);

SQL aggregate functions

A
Akina, 2021-04-13
@Akina

SELECT DISTINCT class
FROM tablename t1
WHERE NOT EXISTS ( SELECT NULL
                   FROM tablename t2
                   WHERE t1.class = t2.class
                     AND t2.mark != 5 )

The query assumes that there are no records where the score is missing (mark IS NULL).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question