Search code examples
mysqlsqlaverage

Exclude a value from AVG in SQL


I have a table where i have to find the avg price of an item, the problem is that i have to exclude a payment option from the avg

lets say the table goes like this Example

enter image description here

I want to remove cash payments from this avg


Solution

  • Just add a WHERE statement to filter out cash payments.

    SELECT AVG(total)
    FROM yourtable
    WHERE payment != 'cash'