26 lines
469 B
MySQL
26 lines
469 B
MySQL
|
with
|
||
|
fp as (
|
||
|
SELECT
|
||
|
od.part,
|
||
|
sum(fb_val_loc * r_rate) sales,
|
||
|
sum(fb_cst_loc * c_rate) scost
|
||
|
FROM
|
||
|
rlarp.osmf_dev od
|
||
|
LEFT OUTER JOIN rlarp.itemmv m ON
|
||
|
m.item = od.part
|
||
|
WHERE
|
||
|
m.item is null
|
||
|
GROUP BY
|
||
|
od.part
|
||
|
)
|
||
|
SELECT
|
||
|
fp.part,
|
||
|
min(item) item
|
||
|
FROM
|
||
|
fp
|
||
|
LEFT OUTER JOIN rlarp.itemmv m ON
|
||
|
substring(m.item,1,11) = fp.part
|
||
|
GROUP BY
|
||
|
fp.part
|
||
|
ORDER BY
|
||
|
fp.part
|