Project

일반

사용자정보

View 테이블 » 이력 » 버전 3

김지영, 2023-07-19 07:50

1 1 김지영
h1. View 테이블
2
3
<pre>
4
CREATE VIEW project_summary_view AS
5 2 김지영
select t1.*,
6
       IFNULL(t2.worker_cnt, 0) as worker_cnt, IFNULL(t2.insp_cnt, 0) as insp_cnt, IFNULL(t2.uploader_cnt, 0) as uploader_cnt
7
from (
8 1 김지영
    select p.project_id,
9
       p.project_nm,
10
       p.data_type,
11 3 김지영
       count(pd.data_id) as tot_cnt,
12 2 김지영
       iFNULL(SUM(case when data_status_ccd = 'ING' and data_dtl_status_ccd = 'ASSIGN' then 1 else 0 end) , 0) as assign_done_cnt,
13
       iFNULL(SUM(case when data_status_ccd = 'WAIT' and data_dtl_status_ccd = 'WAIT' then 1 else 0 end), 0)  as assign_wait_cnt ,
14
       iFNULL(SUM(case when data_status_ccd = 'ISSUE' then 1 else 0 end) , 0) as issue_cnt ,
15
       iFNULL(SUM(case when data_status_ccd = 'DONE' and data_dtl_status_ccd = 'DONE' then 1 else 0 end), 0)  as done_cnt,
16
       iFNULL(SUM(case when data_type='TABLE' and data_status_ccd = 'ING' and data_dtl_status_ccd = 'APPR' then 1 else 0 end), 0)  as appr_cnt
17 1 김지영
from project p
18 2 김지영
left join project_data pd on p.project_id = pd.project_id
19 1 김지영
group by p.project_id
20
order by p.project_id
21
              ) t1
22
left join (
23
    select project_id,
24
           sum(case when user_role = 'WORKER' then 1 else 0 end) as worker_cnt,
25
           sum(case when user_role = 'INSPECTOR' then 1 else 0 end) as insp_cnt,
26
           sum(case when user_role = 'UPLOADER' then 1 else 0 end) as uploader_cnt
27
    from project_user_assigned pua
28
    join users u on u.user_seq = pua.user_seq
29
    group by project_id
30
    order by project_id
31
) t2 on t1.project_id = t2.project_id ;
32
</pre>