Sqlite选择不同的行作为一个

时间:2013-01-22 16:47:31

标签: sqlite

我一直在寻找可能的解决方案,但我无法在任何地方找到它。我需要的是非常简单的我需要将多行显示为一行。我试过了|| + ||等。

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)

screenshot

2 个答案:

答案 0 :(得分:1)

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

  1. c_data_services
  2. 对数据进行分组
  3. c_dispositivos
  4. 对数据进行分组

    这导致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