T
T
Troodi Larson2018-05-03 19:19:22
MySQL
Troodi Larson, 2018-05-03 19:19:22

Sampling with grouping and sum?

There is a query sketch:

SELECT * FROM `stat` GROUP BY `geo` ORDER BY `good` DESC

It does not work correctly, I can’t understand how to group fields and understand at the same time how to calculate the amount in this grouping.
That is, there are countries (geo) they have conversions (good == 0 || 1) and I need to display data in this form, for example:
RU (`geo`)- 100 (общее количество `good` по гео 'RU')
US - 50
GB - 30

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JimmDiGreez, 2018-05-03
@troodi

SELECT `geo`, sum(`good`) as `sum_good` FROM `stat` GROUP BY `geo` ORDER BY `sum_good` DESC

But it is not exactly)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question