0

I need help writing my SQL query. I've got 3 tables.

Here's a simplified example.

Items

Name Description
First desc 1
Second desc 2

Item Detail

Name Supplier Reorder Level
First Amazon 1
Second Sony 100
Third Sony 10

Item Balance

Name Warehouse Balance
First WH 1 10
Second WH 1 20
Second WH 2 10
Third WH 2 10

This is what I'd like to get as a result:

Item Balance

Supplier Name Reorder Level Balance
Amazon
First 1 10
Subtotal 10
Sony
Second 100 30
Third 10 10
Subtotal 40
Total 50

What's the best way to get this kind of result in MySQL-style SQL?

3
  • 1
    GROUP BY .. WITH ROLLUP
    – Akina
    Sep 26, 2022 at 16:20
  • 1
    The vertical spacing is best done in the client, not SQL.
    – Rick James
    Sep 26, 2022 at 23:46
  • Yeah, I've used python to format and join the SQL results
    – Dawoodjee
    Sep 27, 2022 at 13:46

0

Your Answer

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

Browse other questions tagged or ask your own question.