0

我一直在页面上搜索可能的解决方案,但在任何地方都找不到。我需要的非常简单,我需要将多行显示为一个。我试过了|| + || 等

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)

截屏

4

2 回答 2

1

根据您的评论,我建议采取UNION两个单独的分组:

  1. 对数据进行分组c_data_services
  2. 对数据进行分组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)
于 2013-01-22T18:51:50.190 回答
0

COALESCE 函数返回第一个非值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
于 2013-01-22T18:51:39.297 回答