Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-16
2
Medium Priority
?
657 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 2000 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 44

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Ready to get certified? Check out some courses that help you prepare for third-party exams.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

782 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