Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8272725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:13:41+00:00 2026-06-08T07:13:41+00:00

I have this query: SELECT ( SELECT purchase_code FROM qa_suppliers_invoices a WHERE a.supplier_invoice_code =

  • 0

I have this query:

SELECT (
        SELECT purchase_code 
        FROM qa_suppliers_invoices a 
        WHERE a.supplier_invoice_code = b.item_invoicecodesupplier
       ) AS purchase_code, 
      item_code, 
      status_code, 
      itempurchase_quantity, 
      item_costprice 
FROM qa_items_purchases b
ORDER BY purchase_code LIMIT 0,20000;

It return the following data
enter image description here

I want to GROUP like a Purple color line using (item_code) row, i want to add all the (itempurchase_quantity) making reference to (status_code) row then apply this ecuation (status_15 – status_16) also like the image.

I want this result, GROUP():

purchase_code  item_code  status_code  itempurchase_quantity  item_costprice
1              1506       15           713                    126.94
2              1503       16           12                     0.00
2              1683       15           9                      25.28
2              1931       15           60                     0.00

In the case of item_code(1997) not exist status_code = 15 There is thus return a negative number(-9) then you do not need to show.

2              2325       16           50                     849.97

NOTE:
I need to disappear all 16 status_code

Demo data to play with query at sqlfiddle

UPDATE:
This is a picture detailing what I need:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:13:42+00:00Added an answer on June 8, 2026 at 7:13 am
    SELECT 
          a.purchase_code,
          b.item_code, 
          '15' AS status_code,
          SUM(
            CASE b.status_code 
                WHEN 15 THEN b.itempurchase_quantity
            ELSE 
                - (b.itempurchase_quantity) 
            END) 
            AS itempurchase_quantity,
          b.item_costprice
    FROM qa_items_purchases b
        INNER JOIN qa_suppliers_invoices a 
            ON a.supplier_invoice_code = b.item_invoicecodesupplier
    GROUP BY purchase_code, b.item_code, b.item_costprice
        HAVING itempurchase_quantity > 0
        ORDER BY purchase_code 
        LIMIT 0,20000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: select qa_returns_items.item_code, (CASE status_code WHEN 11 THEN (qa_returns_items.item_quantity - qa_returns_residues.item_quantity)
I have this query: SELECT * From checkfinale where AssociateID = 51 AND `CompletedDate`
I have this query: select BUnit, value from myTable where BUnit in (555,556,557,558) and
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
I have this query. SELECT purchase_log.id, purchase_log.date_purchased, purchase_log.total_cost, purchase_log.payment_status, cart_contents.product_name, members.first_name, members.last_name, members.email FROM
I have this query: SELECT * FROM table WHERE key LIKE '1,2,3,%' OR key
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
i have this query: SELECT `completed`.`ID` AS `ID`,`completed`.`level` AS `level`,`completed`.`completed_in` AS `completed_in`, COUNT(1) AS
I have this query SELECT zip, ( 3959 * acos( cos( radians(34.12520) ) *
I have this query: Select (Country.Name + ', ' + City.Name) as Location ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.