sql:
select (case when order_id != 0 then order_id end) as order_id,
(case when order_id = 0 then other_field end) as other_field,
count(*)
from table t
group by (case when order_id != 0 then order_id end),
(case when order_id = 0 then other_field end);
the case condition (case when order_id != 0 then order_id end) and (case when order_id = 0 then other_field end) must repeat in select query, and I have tried to add as field in group by condition like
select order_id,
other_field,
count(*)
from table t
group by (case when order_id != 0 then order_id end) as order_id,
(case when order_id = 0 then other_field end) as order_field;
but it shows error, is it possible to use case condition once? because perhaps the condition will become too long to understand.