subquery sql, 2 or more select statement in select statement and grouping by

Viewed 25
select event_site,
    payor,
    name_policy,
    sum(item_qty) as dsh,
    count(distinct event_id) as ttl_show,
    count(distinct pres_ind_id) as unique_served,
    (
        select count(distinct event_id)
        from cart_item_funder_policy_worker
        where event_status like 'No%'
    ) as no_show
from cart_item_funder_policy_worker
where date_part('year', event_time) = 2022
group by event_site,
    payor,
    name_policy;

what is wrong in this query?

i want to get no show as well for each site, payor and name_policy but my query is giving count of no show as one number for each group by items.

any help is appreciated.

table contains: payor varchar, event_site varchar, name_policy varchar, item_qty int, pres_ind_id int, event_id int, event_status varchar. in short what i want is a column named no_show with distinct count of event_id where event_status is "no_show, and a column named show with distinct count of event id where event_status is "show", and a column named dsh with sum of item_qty where event_status is "show, and a column named no_show_hrs with sum of item_qty where event_status is "show", and group them by event_site, payor, name_policy all should be for year 2022.

event_site = canada, usa, india, greenland. payor = govt, funder, client, none. name_policy= A, B, C, D. event_id = 222, 333, 444, 555. item_qty = $30, $12, $23, $10. pres_ind_id = 3, 4, 5, 6. event_status = show, show, no_show, show

0 Answers
Related