0

I am stuck on MySql Query execution! I created one table called 'WO'. From this table, there are 3 columns

  1. Order QTY (Actual Quantity for the order)
  2. Receive Qty (Actual Quantity that has been received)
  3. Pending Qty. (Quantity that will be received)

I can add some of my row results. But my target is, if Order QTY=Receive QTY, then this row will not be shown during execution. But I failed to capture this part! Need your valuable advice to solve this part.

Below is my code and output in a picture.

SELECT 
    id,
    ind,
    WONO,
    PRODUCT,
    SUM(QTY) as "Order_QTY",
    SUM(Rec_QTY) as "Received",
    SUM(QTY-Rec_QTY) as "Pending",
    UNIT 
FROM 
    wo 
WHERE 
    Inhouse_Status!="IN-HOUSED" 
Group by 
    ind 
ORDER BY 
    ind DESC

enter image description here

0

2 Answers 2

1

You just have to add condition in you WHERE clause

SELECT 
    id,
    ind,
    WONO,
    PRODUCT,
    SUM(QTY) as "Order_QTY",
    SUM(Rec_QTY) as "Received",
    SUM(QTY-Rec_QTY) as "Pending",
    UNIT 
FROM 
    wo 
WHERE 
    Inhouse_Status!="IN-HOUSED" AND Order_QTY != Received
Group by 
    ind 
ORDER BY 
    ind DESC
0

You may filter rows using a where condition eg WHERE Order QTY <> Receive QTY or since you are using a group by to sum total Order QTY you may filter the total using a having clause eg WHERE SUM(QTY) <> SUM(Rec_QTY).

Your query could look like:

SELECT 
    ind,
    WONO,
    PRODUCT,
    SUM(QTY) as "Order_QTY",
    SUM(Rec_QTY) as "Received",
    SUM(QTY-Rec_QTY) as "Pending",
    UNIT 
FROM 
    wo 
WHERE 
    Inhouse_Status!="IN-HOUSED" 
Group by 
    ind, WONO,PRODUCT, UNIT
HAVING
    SUM(QTY) <> SUM(Rec_QTY)
ORDER BY 
    ind DESC
0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.