forecast_api/inquirey/over_under_ship.sql

26 lines
918 B
MySQL
Raw Permalink Normal View History

2021-04-13 16:01:00 -04:00
SELECT
calc_status
,flag
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty < 0) overship
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty > 0) undership
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND fb_qty = 0) no_units
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND dhincr = 'C') credits
,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND "ddord#" = 0 ) no_units
2021-04-13 16:01:00 -04:00
FROM
rlarp.osmf_dev
2021-04-13 16:01:00 -04:00
WHERE
(
(
oseas = 2021
AND odate <@ daterange('2020-06-01','2021-04-11')
)
OR sseas = 2021
)
AND fs_line = '41010'
--AND version = 'ACTUALS'
--AND calc_status = 'CLOSED'
--AND flag = 'REMAINDER'
2021-04-13 16:01:00 -04:00
GROUP BY
calc_status,
flag;