Click here to Skip to main content
16,022,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my table has following

Tablename  Temporderdetails
Billno    Item         quantity     
11        Chappathi      2
11        Vennila        1
11        Bonda          1
11        Chappathi      1


I want to get like following from above table
Billno    Item       quantity
11        Chappathi     3
11         Vennila      1
11         Bonda        1


How to do it please help me anybody

Thank you
Posted

SQL
select distinct Billno,Item,sum(Quantity) from Temporderdetails group by Billno,Item,Quantity
 
Share this answer
 
you can derive many ways to get the desired output.

Simply
SELECT Billno,Item, SUM(Quantity) FROM Temporderdetails group by Item, Billno


Complex
SELECT DISTINCT Billno,Item,(SELECT SUM(Quantity) FROM Temporderdetails WHERE item=tn.item GROUP BY Item) FROM Temporderdetails tn

recommended, don't go for complex queries.
 
Share this answer
 
v2
this is simple group by...

select billno, item, sum(quantity) from Temporderdetails group by billno, item

have a look at the following tutorial:

http://www.sql-tutorial.net/SQL-GROUP-BY.asp[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900