대시 보드 뷰 수정
This commit is contained in:
@@ -564,7 +564,7 @@ AS SELECT daily_record.household_seq,
|
||||
-- ============================================
|
||||
-- DROP VIEW public.v_household_monthly_target_days;
|
||||
CREATE OR REPLACE VIEW public.v_household_monthly_target_days
|
||||
AS WITH param_matrix AS (
|
||||
as WITH param_matrix AS (
|
||||
SELECT h.seq AS household_seq,
|
||||
r.record_month,
|
||||
EXTRACT(day FROM date_trunc('month'::text, to_date(r.record_month::text, 'YYYYMM'::text)::timestamp with time zone) + '1 mon -1 days'::interval)::integer AS last_day
|
||||
@@ -575,7 +575,8 @@ AS WITH param_matrix AS (
|
||||
)
|
||||
SELECT p.household_seq,
|
||||
p.record_month,
|
||||
count(*) AS total_day_groups
|
||||
count(*) AS total_day_groups,
|
||||
case when to_char(CURRENT_DATE,'YYYYMM')::text = p.record_month then sum(case when to_char(CURRENT_DATE,'dd')::integer >= g.start_day then 1 else 0 end)else count(*) end as current_day_groups
|
||||
FROM param_matrix p
|
||||
JOIN daily_day_group g ON g.start_day <= p.last_day
|
||||
GROUP BY p.household_seq, p.record_month;
|
||||
@@ -675,14 +676,16 @@ AS WITH ranked_visits AS (
|
||||
-- ============================================
|
||||
-- DROP VIEW public.v_monthly_completion_rate;
|
||||
CREATE OR REPLACE VIEW public.v_monthly_completion_rate
|
||||
AS SELECT d.household_seq,
|
||||
as SELECT d.household_seq,
|
||||
d.record_month,
|
||||
COALESCE(c.completed_day_groups, 0::bigint) AS completed_day_groups,
|
||||
d.total_day_groups,
|
||||
round(COALESCE(c.completed_day_groups, 0::bigint)::numeric * 100::numeric / NULLIF(d.total_day_groups, 0)::numeric, 3) AS completion_rate
|
||||
FROM v_household_monthly_target_days d
|
||||
round(COALESCE(c.completed_day_groups, 0::bigint)::numeric * 100::numeric / NULLIF(d.total_day_groups, 0)::numeric, 3) AS completion_rate,
|
||||
d.current_day_groups,
|
||||
round(COALESCE(c.completed_day_groups, 0::bigint)::numeric * 100::numeric / NULLIF(d.current_day_groups, 0)::numeric, 3) AS current_completion_rate
|
||||
FROM v_household_monthly_target_days d
|
||||
LEFT JOIN v_household_monthly_completed_days c ON d.household_seq = c.household_seq AND d.record_month::text = c.record_month::text
|
||||
ORDER BY d.household_seq, d.record_month;
|
||||
ORDER BY d.household_seq, d.record_month;
|
||||
|
||||
|
||||
-- ============================================
|
||||
|
||||
Reference in New Issue
Block a user