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
|
CREATE MATERIALIZED VIEW TRESOR01.CASHIER_DIFFERENCE
BUILD IMMEDIATE
REFRESH FORCE ON COMMIT
AS
select t.day_cashier_id, sum(real_amount * (case when type = 'D' then 1 else -1 end)) as CASHIER_DIFERENCE, t.HAVE_WORKED
from
(
select a.day_cashier_id, sum(a.real_amount) as real_amount, r.type as type,
case when exists
(
select 1 from amount a2
where a2.day_cashier_id = a.day_cashier_id
and a2.rubric_code <> 'FONDSO'
and a2.rubric_code <> 'FONDSF'
and a2.theoretic_amount <> 0
and a2.theoretic_amount is not null
)
Then 'Y'
Else 'N'
End as HAVE_WORKED
from amount a, day_rubric dr, shop_rubric sr, rubric r
where r.rubric_id = sr.rubric_id
and sr.shop_rubric_id = dr.shop_rubric_id
and dr.day_rubric_id = a.day_rubric_id
and a.day_cashier_id = a.day_cashier_id
group by r.type, a.day_cashier_id
) t
group by t.day_cashier_id, t.HAVE_WORKED; |
Partager