x

How do you bring back multiple sub totals based on one column?

I need to query for part_number and transfer_type to calculate subtotals for [quantity_received], [quantity_transferred], [quantity_sold] in a query. The basis for these values is part_number and transfer_type. So for each part_number i need the different transfer_types and the subtotals for the quantities.

Ex.

 +-------------+---------------+-------------------+----------------------+---------------+
 | Part_Number | Transfer_Type | quantity_received | quantity_transferred | quantity_sold |
 +-------------+---------------+-------------------+----------------------+---------------+
 | 123         | Invoice       | 32                | 20                   | 10            |
 | 123         | Receipt       | 12                | 2                    | 10            |
 | 345         | Receipt       | 2                 | 2                    | 0             |
 +-------------+---------------+-------------------+----------------------+---------------+

more ▼

asked Mar 16 at 02:52 PM in Default

avatar image

dayjaa3
1

what does the base data look like?

Mar 17 at 09:01 AM Kev Riley ♦♦

Can you supply with some dummy data so we can have a look?

Mar 20 at 02:05 PM mdawini
(comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1089

asked: Mar 16 at 02:52 PM

Seen: 35 times

Last Updated: Mar 20 at 02:05 PM

Copyright 2017 Redgate Software. Privacy Policy