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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| select
count(distinct(sub1.nombre)) as "nombre",
count(distinct(sub2.nombresold)) as "nombresold",
count(distinct(sub3.totalsold)) as "totalsold",
count(distinct(sub4.Pnombresold)) as "Pnombresold"
from CSWO_WO wo
Inner join CSWO_WOEQPT we on we.WO_ID=wo.id
inner join CSWO_WORESOURCES wb on wb.wo_id=wo.id
inner join CSEQ_EQUIPMENT eq on eq.ID=we.eqpt_id
left outer join (
select
wo.code as "nombre"
from CSWO_WO wo
inner join CSWO_WOEQPT we on we.WO_ID=wo.id
inner join CSWO_WORESOURCES wb on wb.wo_id=wo.id
inner join CSEQ_EQUIPMENT eq on eq.ID=we.eqpt_id
WHERE wo.STATUS_CODE in('REQUEST','AWAITINGESTIMATE','AWAITINGVALID','AWAITINGITEM','AWAITINGREAL','INPROGRESS','PAUSE','FINISHED','CLOSED','ARCHIVED','CANCEL')
and wb.PLANNINGDATE>=cast ('2019-05-05' as date) and wb.PLANNINGDATE<=cast ('2019-05-13' as date)
group by wo.code ) sub1 on sub1.nombre=wo.code
left outer join (
select
wo.code as "nombresold"
from CSWO_WO wo
inner join CSWO_WOEQPT we on we.WO_ID=wo.id
inner join CSWO_WORESOURCES wb on wb.wo_id=wo.id
inner join CSEQ_EQUIPMENT eq on eq.ID=we.eqpt_id
inner join CSWO_WOSTATUS wc on wc.ORIGIN_ID=wo.id
WHERE wo.STATUS_CODE in('FINISHED','CLOSED','ARCHIVED')
and wc.STATUS_CHANGEDDATE>=cast ('2019-05-05' as date) and wc.STATUS_CHANGEDDATE<=cast ('2019-05-13' as date)
and wb.PLANNINGDATE>=cast ('2019-05-05' as date) and wb.PLANNINGDATE<=cast ('2019-05-13' as date)
group by wo.code ) sub2 on sub2.nombresold=wo.code
left outer join (
select
wo.code as "totalsold"
from CSWO_WO wo
inner join CSWO_WOEQPT we on we.WO_ID=wo.id
inner join CSWO_WORESOURCES wb on wb.wo_id=wo.id
inner join CSEQ_EQUIPMENT eq on eq.ID=we.eqpt_id
inner join CSWO_WOSTATUS wc on wc.ORIGIN_ID=wo.id
WHERE wo.STATUS_CODE in('FINISHED','CLOSED','ARCHIVED')
and wc.STATUS_CHANGEDDATE>=cast ('2019-05-05' as date) and wc.STATUS_CHANGEDDATE<=cast ('2019-05-13' as date)
group by wo.code ) sub3 on sub3.totalsold=wo.code
left outer join (
select
wo.code as "Pnombresold"
from CSWO_WO wo
inner join CSWO_WOEQPT we on we.WO_ID=wo.id
inner join CSWO_ACTIONTYPE wd on wd.id=wo.ACTIONTYPE_ID
inner join CSWO_WORESOURCES wb on wb.wo_id=wo.id
inner join CSEQ_EQUIPMENT eq on eq.ID=we.eqpt_id
inner join CSWO_WOSTATUS wc on wc.ORIGIN_ID=wo.id
WHERE wo.STATUS_CODE in('FINISHED','CLOSED','ARCHIVED') and wd.code = ('PREVENTIF')
and wc.STATUS_CHANGEDDATE>=cast ('2019-05-05' as date) and wc.STATUS_CHANGEDDATE<=cast ('2019-05-13' as date)
group by wo.code ) sub4 on sub4.Pnombresold=wo.code
where eq.code = ? |
Partager