I store some values in postgresql in varchar format. The values that I store in the varchar data type are either integer or numeric. I store 6 values for each user. I want to take only 4 greatest values and find their average. For example if store the values 13, 14, 6, 13, 13, 17 and I use this query to get the 4 greatest values,
select value from master where name='$name' desc limit 4;
it returns 6,17,14,13. I have to get 17,14,13,13. How can i do this, and if i store a numeric value like 13.5 the value 17,14,13.5,13 should be fetched.
getting the correct values
Moderator: General Moderators
-
rochakchauhan
- Forum Newbie
- Posts: 5
- Joined: Tue Apr 26, 2005 4:32 am
try this....
select value from master where name='$name' desc ORDER BY value limit 4;
-
niceguy_reddy
- Forum Newbie
- Posts: 7
- Joined: Fri Feb 04, 2005 9:01 am
-
Bennettman
- Forum Contributor
- Posts: 130
- Joined: Sat Jun 15, 2002 3:58 pm
Last post had incorrect ordering syntax:
Code: Select all
SELECT value FROM master WHERE name='$name' ORDER BY value DESC LIMIT 4;