Solved

How to sum the quantity or price on SQL Table SUM ()

Posted on 2013-01-16
2
614 Views
Last Modified: 2013-01-16
Our Drug Table has only 3 columns like GenericCode, DrugName, Qty.

SUM(QTY) is the Column which i expect to be along with my Select Query


GenericCode       DrugName         Qty           SUM(Qty)
102010                 ABC                  10                   40
102010                 ABC                  20                    40
102010                 ABC                  10                    40

102111                 EFG                  10                     20
102111                 EFG                  10                     20
0
Comment
Question by:chokka
2 Comments
 
LVL 41

Accepted Solution

by:
ralmada earned 500 total points
ID: 38783895
use this

select *, sum(qty) over (partition by GenericCode) from yourtable

More details:

http://msdn.microsoft.com/en-us/library/ms189461(v=sql.100).aspx
0
 
LVL 42

Expert Comment

by:zephyr_hex (Megan)
ID: 38783909
select DrugName,sum(Qty) from DrugTable group by DrugName

i'm not clear from your data set whether you also want to group by GenericCode.  if that's the case, then
select GenericCode,DrugName,sum(Qty) from DrugTable group by GenericCode,DrugName
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now