根据日期选择不同的内部数组

时间:2016-01-08 10:33:18

标签: sql arrays postgresql distinct

所以我想从我的数据库(postgressql)显示值(明显) 这是我的代码:

SELECT distinct t.*, round(SUM(percentage)OVER (order by agentname rows between unbounded preceding and current row),3) AS cumulative
FROM (
  SELECT 
    a.*,
    COUNT(*) AS frequency,
   round(COUNT(*) * 100.00 / SUM(COUNT(*)) OVER (),4) AS percentage
  FROM 
      (select agentname,inputdate, unnest(array[ WSalamPembuka,WKonfirmasiNamaCust, WVerifikasiData,WKemampuanBertanya,WProductKnowledge,WSolusi,WAlternativeSolusi,WSistemPelaporan,WEmpati,WResponsif,WRamahSopan,WPercayaDiri,WHoldCall,WOfferHelp,WPenutup]) as weakness                        
                from call )as a 
                  WHERE a.agentname like '%wendra%' and a.weakness is not null and a.weakness !='' and a.inputdate between '01/12/2015' and  '08/01/2016'
                  group by a.agentname,a.weakness,a.inputdate
                  order by frequency desc
                ) AS t
                ORDER BY frequency DESC 

我得到的结果是 enter image description here

你可以看到我在这里得到了重复的数据。我希望它像:

enter image description here

解决这个问题的任何技巧?先谢谢

1 个答案:

答案 0 :(得分:3)

您获得重复的原因是因为您按输入日期进行分组:

group by a.agentname,a.weakness,a.inputdate

只需从inputdate子句(以及外部group by子句)中删除select,您就可以获得所需的结果(通过注释{注意我的更改} {1}}):

inputdate