Click here to Skip to main content
14,970,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table master with attributes:ID,name,amount,date

on 04/05/2010 I entered the the data as (100,'Albert',50000,'04/05/2010')
on 05/05/2010 I entered the the data as (101,'Perera',20000,'05/05/2010')
on 06/05/2010 I entered the the data as (105,'Dixon',50000,'06/05/2010')
on 07/05/2010 I entered the the data as (100,'Albert',80000,'07/05/2010')
on 08/05/2010 I entered the the data as (105,'Dixon',10000,'08/05/2010')
on 09/05/2010 I entered the the data as (100,'Albert',90000,'09/05/2010')
on 10/05/2010 I entered the the data as (100,'Albert',20000,'10/05/2010')

I required the result as below

Id Name Amount

100 Albert 240000
101 Perara 20000
105 Dixon 60000
Posted

You need to use "Group By" clause. :)
Here you go :
select ID,name,sum(amount) from master group by ID,name
   
SQL
Select ID, name, SUM(amount)
From myTable
Where date between ('04/05/2010') and ('10/05/2010')
Group By ID, name


Please buy a book and read. It will help you in learning new things and development.
   

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