Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-16
2
Medium Priority
?
646 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

715 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