getting the correct values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
niceguy_reddy
Forum Newbie
Posts: 7
Joined: Fri Feb 04, 2005 9:01 am

getting the correct values

Post by niceguy_reddy »

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.
rochakchauhan
Forum Newbie
Posts: 5
Joined: Tue Apr 26, 2005 4:32 am

try this....

Post by rochakchauhan »

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

Post by niceguy_reddy »

if i give order by then it returns 8,13,14,17 when the values in the database are 13,8,14,12,13,17.
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

Last post had incorrect ordering syntax:

Code: Select all

SELECT value FROM master WHERE name='$name' ORDER BY value DESC LIMIT 4;
Post Reply