Skip to content
Advertisement

I need to find the average of all records (Qty) which related Supplier numbers (SNo) if there have at least only one record

I need to find the average of all records (Qty) which related Supplier numbers (SNo) as S1, S2 ..etc. even if there have at least only one record to true the condition

this query select only one record and the query checking condition before get the average

this is my table :

I need to select average qty from the table which more than 50 & less than 100. but my query select only record only.
But I need to take result as:

So S2 haven’t any qty between 50 and 100. so that’s why it should be rejected.

Advertisement

Answer

You need to check in the HAVING clause if there is a row for that Supplier which satisfies the condition:

See the demo.
Results:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement