1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| SQL> with entree as (
2 select 1 as id, to_date('01/12/2013','dd/mm/yyyy') as date_ent from dual union all
3 select 2 , to_date('10/12/2013','dd/mm/yyyy') from dual union all
4 select 3 , to_date('15/12/2013','dd/mm/yyyy') from dual union all
5 select 4 , to_date('20/12/2013','dd/mm/yyyy') from dual union all
6 select 5 , to_date('23/12/2013','dd/mm/yyyy') from dual
7 ),
8 sortie as (
9 select 1 as id, 1 as id_ent , to_date('16/12/2013','dd/mm/yyyy') as date_sor from dual union all
10 select 2 , 4 , to_date('23/12/2013','dd/mm/yyyy') from dual
11 )
12 SELECT count(e.id) AS total, count(s.id) AS Sortie, trunc(count(s.id)/count(e.id)*100) AS Pourcentage
13 FROM entree e
14 LEFT JOIN sortie s
15 ON s.id_ent = e.id
16 AND (s.date_sor - e.date_ent) < 5
17 WHERE to_char(e.date_ent,'MM/YYYY')='12/2013';
TOTAL SORTIE POURCENTAGE
---------- ---------- -----------
5 1 20
SQL> with entree as (
2 select 1 as id, to_date('01/12/2013','dd/mm/yyyy') as date_ent from dual union all
3 select 2 , to_date('10/12/2013','dd/mm/yyyy') from dual union all
4 select 3 , to_date('15/12/2013','dd/mm/yyyy') from dual union all
5 select 4 , to_date('20/12/2013','dd/mm/yyyy') from dual union all
6 select 5 , to_date('23/12/2013','dd/mm/yyyy') from dual
7 ),
8 sortie as (
9 select 1 as id, 1 as id_ent , to_date('16/12/2013','dd/mm/yyyy') as date_sor from dual union all
10 select 2 , 4 , to_date('23/12/2013','dd/mm/yyyy') from dual
11 )
12 SELECT count(e.id) AS total,
13 sum(case when s.date_sor - e.date_ent < 5 then 1 end) AS Sortie,
14 trunc(sum(case when s.date_sor - e.date_ent < 5 then 1 end) / count(e.id)*100) AS Pourcentage
15 FROM entree e
16 LEFT JOIN sortie s ON s.id_ent = e.id
17 WHERE to_char(e.date_ent,'MM/YYYY')='12/2013';
TOTAL SORTIE POURCENTAGE
---------- ---------- -----------
5 1 20
SQL> |
Partager