私はこのSQL構文を使用しています。私たちにアクセスするのに利用された情報源の数を示します。数字をカウントではなく百分率で表示したい(100%のうち)。どのように私はパーセントでのカウントを表示するために私の声明を得ることができます、ヘルプDatabasersを提供してください。週と年のパーセンテージを表示
声明:
select coalesce(t2.Source, 'Total') as "Source",
coalesce(count(case when Week = date_trunc('week', now())::date - 1
then t1."Source" end),0) "This Week",
coalesce(count(t1.Source),0) "YTD"
from infosys t2
left join infocentertracker t1
ON t1.Source = t2.Source
and Week >= DATE '01/01/2017'
and Week < DATE '01/01/2018'
and Project_ID = 'PCR'
group by rollup(t2.Source)
結果:
Source This Week YTD This Week YTD
Billboard 0 0 0% 0%
Builder 2 8 20% 12%
Community Website 0 2 0% 3%
Drive-by 6 35 60% 52%
Non-Disclosed 0 1 Requested --> 0% 2%
Other Website 0 4 0% 6%
Radio 0 0 0% 0%
Realtor 1 13 10% 19%
Resident Referral 1 3 10% 4%
Return Visitor 0 0 0% 0%
RPG Website 0 0 0% 0%
Social Media 0 2 0% 3%
Total 10 68 100% 100%
なぜ「by rollup」を使用していますか? – McNets
クエリの下部に合計を表示します。 –
おそらくウインドウ関数が必要です:http://stackoverflow.com/a/6207658/3430807 – Andreas