L
L
LakeForest2022-04-18 13:19:04
PostgreSQL
LakeForest, 2022-04-18 13:19:04

How to write an sql-query for grouping by conditions: more than the average value, less than the average value?

Table

grp | val | date
------------------------
t     |   1   |   01-01-1990
f     |   3   |   02-01-1990
t     |   2   |   03-01-1990
f     |   2  |   02-01-1990
f     |   1  |   02-01-1990


You need to get a table like this:
Промежуток           | t | f | sum строк
--------------------------------------------------
больше среднего val | 2 | 2,5 | 2
меньше среднего val | 1 | 1   | 1
--------------------------------------------------
итого              |  2  | 3  | 5

The totals are the number of lines grouped by grp and total.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question