My database is like this
no name age
1 nan 23
2 nad 10
3 mam 10
4 rgh 10
5 hui 21
i want to add age which is between the no 2 to 4
result will be 30 .
This is query to retrieve data between 2 to 4
Select * from table where no between 2 and 4 but i dnt know how to add the age value ..please say query for this
Hemant SrivastavaPosted Jul 26, 2013, 2:03 PM
select SUM(no)
from table
where no between 2 and 4
Note: In the select clause , you can not add other individual column( e.g name) since it's an aggregate function.
Sanjeeb LenkaPosted Jul 26, 2013, 2:12 PM
may be i am confused about your problem 1st. you can use an aggregate function to do that
ex:if age field is integer
select SUM(age) as totalage
from table
where no between 2 and 4
or if age field in varchar use this
select SUM(cast(age as int)) as totalage from table
where no between 2 and 4
Nandhini JayachandranPosted Jul 26, 2013, 2:04 PM
Nandhini JayachandranPosted Jul 26, 2013, 1:53 PM
Hemant SrivastavaPosted Jul 26, 2013, 1:44 PM
UPDATE table
SET no = no + 20
where no between 2 and 4