gpt4 book ai didi

sql - 如何根据日期在数组中选择不同的?

转载 作者:行者123 更新时间:2023-11-29 12:04:26 25 4
gpt4 key购买 nike

我想(明确地)显示来 self 的数据库 (PostgreSQL) 的值这是我的代码:

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

有什么技巧可以解决这个问题吗?

最佳答案

你得到重复项的原因是因为你按输入日期分组:

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

只需从 group by 子句(以及外部 select 子句)中删除 inputdate,您就会得到想要的结果(通过注释掉 inputdate 来注意我的更改):

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

关于sql - 如何根据日期在数组中选择不同的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34674841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com