Reputation: 31
I've been searching the page for possible solutions but I can't find it anywhere.. What I need is pretty simple I need multiple rows to be displayed into one. I have tried || + ||, etc.
select c_category_in, c_data_services, c_dispositivos, c_averia as 'Sub-Category', count() as 'Total'
from tickets
group by c_category_in,c_averia,c_data_services,c_dispositivos
having (Total > 1)
Upvotes: 0
Views: 89
Reputation: 16054
Based on your comments I would recommend taking a UNION
of two separate groupings:
c_data_services
c_dispositivos
This results in a SELECT
as following:
select c_category_in, c_data_services as 'Sub-Category', count() as 'Total'
from tickets
group by c_category_in, c_data_services
having (Total > 1)
union all
select c_category_in, c_dispositivos as 'Sub-Category', count() as 'Total'
from tickets
group by c_category_in, c_dispositivos
having (Total > 1)
Upvotes: 1
Reputation: 180020
The COALESCE function returns the first non-NULL
value:
SELECT c_category_in,
COALESCE(c_data_services, c_dispositivos) AS SubCategory,
COUNT(*) AS Total
FROM tickets
GROUP BY c_category_in, SubCategory
HAVING Total > 1
Upvotes: 0