01.
SELECT
distinct
product.PRO_ID,PRO_TYPE_NAME,BRAND_NAME,MODEL_NAME,COLOR_NAME,quote.QT_ID,QT_AMOUNT,quotedetail.OK_AMOUNT,order_detail.ORD_NO
02.
FROM
quote,quotedetail,brand,color,model,product_type,product,product_color,`
order
`,`order_detail`
03.
WHERE
order
.ORD_ID =
'ORD100002'
and
quote.QT_ID = quotedetail.QT_ID
and
product_color.PRO_ID = quotedetail.PRO_ID
04.
and
product.PRO_ID = product_color.PRO_ID
and
product.BRAND_ID = brand.BRAND_ID
and
product_color.COLOR_ID = color.COLOR_ID
05.
and
product.MODEL_ID = model.MODEL_ID
and
product.PRO_TYPE_ID = product_type.PRO_TYPE_ID
and
product_color.COLOR_ID = quotedetail.COLOR_ID
06.
and
product_color.
NO
= quotedetail.
NO
and
quotedetail.QT_ID = order_detail.QT_ID
and
order
.ORD_ID = order_detail.ORD_ID
and
order_detail.QT_NO = quotedetail.QT_NO
07.
and
order
.ORD_ID
in
08.
(
SELECT
o.ORD_ID,o.ORD_NO,o.OK_AMOUNT,IFNULL(
SUM
(REV_AMOUNT),0)
AS
AMOUNT
09.
FROM
order_detail o
LEFT
OUTER
JOIN
receive_detail r
ON
r.ORD_ID=o.ORD_ID
AND
r.ORD_NO=o.ORD_NO
10.
WHERE
o.ORD_ID =
'ORD100002'
GROUP
BY
o.ORD_ID,o.ORD_NO
HAVING
IFNULL(
SUM
(REV_AMOUNT),0)<o.OK_AMOUNT)