Home > Enterprise >  Return result only if there are 10 rows or more
Return result only if there are 10 rows or more

Time:10-11

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?

CodePudding user response:

Try this case expression.

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