K
K
Kirill Petrov2017-05-26 17:37:19
MySQL
Kirill Petrov, 2017-05-26 17:37:19

How to write a query with a condition and GROUP BY in MySQL?

Greetings. I am writing this query:

SELECT reklama_source_id, SUM(price) as `sum_price` FROM `applications` WHERE `sum_price` > 20 GROUP BY `reklama_source_id`

I want to select advertising sources that have generated more than 20 income,
but the database swears with an error:
#1054 - Неизвестный столбец 'sum_price' в 'where clause'

How to make a request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-05-26
@Recosh

On WHERE this column is not defined yet, it appears only after GROUP BY. Use HAVING.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question