incompletablefuture
incompletablefuture

Reputation: 124

Return result only if there are 10 rows or more

I have a query:

select AVG(tickets_number)
from TABLE_ONE
where ofd_id = :ofdId and launch_id in
(select id from TABLE_TWO where is_actual = 1 and is_matching_completed = 1)

But I need to calculate average value only if there are at least 10 rows from this query, otherwise I have to return NULL.

How can I do this?

Upvotes: 1

Views: 39

Answers (1)

O. Jones
O. Jones

Reputation: 108641

Try this case expression.

select CASE WHEN COUNT(tickets_number) >= 10
            THEN AVG(tickets_number)
            ELSE NULL END average
from TABLE_ONE ...

Upvotes: 4

Related Questions