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