Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Talahaski
Enchanter


Joined: 10 Oct 2000
Posts: 656
Location: USA

PostPosted: Sun Apr 11, 2004 9:39 pm   

Database query - return max value.
 
Does anybody know an easy way to query a numeric field in the database and return the max value for that field. Its possible that the Max could be zero or that there could be multiple records all with the same max value. For example 10 records could have the value of 2 and another 10 could have the value of 20.

For some additional information, my database name is AL, it has about 10 fields, one of which is called "Grouping". "Grouping" is the numeric field I want to find the max for. With this max value, I plan on doing other computations within the script.

Can anybody help me write something basic to get this value. I'm hoping there is a easier way than having to loop through every record.

Some possibilities I've considered which I'm not sure if they will work yet.
1. Loop through each record
2. Create a view sorted on this field and grab the first record - this might be the best way.
3. use %query to come up with some query that will contain the max. I'm not sure if this will work because the %query only looks at the where clause, what I really need is "select max(Grouping) from AL"
Reply with quote
jessew
Apprentice


Joined: 03 Mar 2003
Posts: 141

PostPosted: Sun Apr 11, 2004 9:57 pm   
 
If I understand correctly I think %dbmax(column[,view]) is what your looking for.

Jesse
Reply with quote
Talahaski
Enchanter


Joined: 10 Oct 2000
Posts: 656
Location: USA

PostPosted: Sun Apr 11, 2004 10:24 pm   
 
doh!

How did I miss that function!

Thanks a bunch.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net