Home » SQL & PL/SQL » SQL & PL/SQL » sum of distinct records data
sum of distinct records data [message #295113] Mon, 21 January 2008 06:31 Go to next message
yogeshyl
Messages: 50
Registered: October 2007
Location: Silvassa
Member
I have the data like this :

Item Name Item Qty
AAA 100
cbg 200
AAA 100
AAA 200
gfh 200
AAA 100

I want to display the distinct records and the sum of its qty as given below:

Item Name Item Qty
AAA 500

Please suggest what will be the sql query to do that?
Re: sum of distinct records data [message #295116 is a reply to message #295113] Mon, 21 January 2008 06:35 Go to previous messageGo to next message
rajavu1
Messages: 1574
Registered: May 2005
Location: Bangalore , India
Senior Member

Group By

Thumbs Up
Rajuvan
Re: sum of distinct records data [message #295146 is a reply to message #295113] Mon, 21 January 2008 08:21 Go to previous messageGo to next message
ramanajv1968
Messages: 168
Registered: December 2005
Location: HYDERABAD
Senior Member
@Yogesh,

You said you want the sum of distinct records
But you have given in your example the total for AAA =500. 
How it is possible ?
The total should be AAA = 400.

do you want the sum based on the item_name .
need clarification.
Re: sum of distinct records data [message #295148 is a reply to message #295146] Mon, 21 January 2008 08:24 Go to previous messageGo to next message
joy_division
Messages: 4643
Registered: February 2005
Location: East Coast USA
Senior Member
It's a minor optical illusion.
Look again. It does add up to 500. I too saw it as 400 when I first looked.

It's like:
Paris in the
the spring

[Updated on: Mon, 21 January 2008 08:25]

Report message to a moderator

Re: sum of distinct records data [message #295149 is a reply to message #295146] Mon, 21 January 2008 08:24 Go to previous messageGo to next message
pablolee
Messages: 2835
Registered: May 2007
Location: Scotland
Senior Member
Look at the example again ramanajv1968. You are wrong about the total
Re: sum of distinct records data [message #295153 is a reply to message #295113] Mon, 21 January 2008 08:30 Go to previous messageGo to next message
ramanajv1968
Messages: 168
Registered: December 2005
Location: HYDERABAD
Senior Member
yes,Got it. :? 
learned from the mistake.

Thanks Buddy,
Re: sum of distinct records data [message #295275 is a reply to message #295146] Mon, 21 January 2008 23:44 Go to previous messageGo to next message
yogeshyl
Messages: 50
Registered: October 2007
Location: Silvassa
Member
The total is 500. I had checked the same.
Re: sum of distinct records data [message #295278 is a reply to message #295113] Mon, 21 January 2008 23:52 Go to previous messageGo to next message
mm_kanish05
Messages: 487
Registered: January 2007
Location: Chennai
Senior Member

hi

I feel u got answer correct

if not

Select Itemname,sum(itemqty)
from yourtable
group by itemname


wbr

kanish
Re: sum of distinct records data [message #295279 is a reply to message #295278] Mon, 21 January 2008 23:54 Go to previous message
yogeshyl
Messages: 50
Registered: October 2007
Location: Silvassa
Member
Thanks Kanish.
Previous Topic: please solve this Query
Next Topic: can i able to view the rows recently inserted?
Goto Forum:
  


Current Time: Thu Dec 08 14:11:23 CST 2016

Total time taken to generate the page: 0.12966 seconds