我一直在寻找可能的解决方案,但我无法在任何地方找到它。我需要的是非常简单的我需要将多行显示为一行。我试过了|| + ||等。
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)
答案 0 :(得分:1)
根据您的评论,我建议您使用UNION
两个单独的分组:
c_data_services
c_dispositivos
这导致SELECT
如下:
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)
答案 1 :(得分:0)
COALESCE function会返回第一个非NULL
值:
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