As in PostgreSql to gruppirovanie for null/not_null?
There is then a field, columnName, which can contain either NULL, or some random string. If you write a normal "GROUP BY columnName", then the sample are grouped by each value of columnName that there is almost unique and the meaning of such groupings there. I would like to divide the sample into 2 parts: one where the field value is NULL and one where any other value. Is it possible?
Saw 3 answer, well, I think elementary, already answered. But why so difficult? group by field_name is null
all. The group by expression, why do it row in the subquery or number? bool by itself is more than enough.
Elian answered on April 19th 20 at 12:30
select count(*),is_null from (
select case when columnName is null then 'null' else 'not null' end as is_null
) t group by is_null;
julie_Medhurst answered on April 19th 20 at 12:32
select group_id, name
where group_id in (
group by 1
having bool_and(name is not null)
SELECT department, COUNT(*) as “Num of employees” , AVG(salary) as “Avg Dept. Salary”
GROUP BY department
Department ORDER BY NULLS LAST;
audreann answered on April 19th 20 at 12:34
Simple group by expression
group by case when my_field is null then 0 else 1 end