mcmuney Posted April 17, 2008 Share Posted April 17, 2008 I've been using this line of code for quite some time, but just recently it stopped working: SELECT * FROM sc_rate_avg WHERE type='$rt' ORDER BY (round((sum_/count_),2)) DESC,count_ DESC LIMIT 1 I've identified that it's no longer working because of this portion of the code: "(round((sum_/count_),2))" Is there another way of achieving the same results? Link to comment https://forums.phpfreaks.com/topic/101511-help-with-select-command/ Share on other sites More sharing options...
mrdamien Posted April 17, 2008 Share Posted April 17, 2008 Well i dont know what sum_ or count_ are in your context, but sum/count mathematically, is an average. SELECT *, AVG(column) FROM sc_rate_avg WHERE type='$rt' ORDER BY AVG(column) DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/101511-help-with-select-command/#findComment-519251 Share on other sites More sharing options...
mcmuney Posted April 17, 2008 Author Share Posted April 17, 2008 Well, I don't think I can use AVG(column) because I have a single row per id and sum_ = score and count_ = how many times, so the true average can be calculated by taking sum_/count_ Link to comment https://forums.phpfreaks.com/topic/101511-help-with-select-command/#findComment-519256 Share on other sites More sharing options...
mrdamien Posted April 17, 2008 Share Posted April 17, 2008 Oh I see. Could you post the error message? There doesn't seem to be anything wrong with the query structure. Link to comment https://forums.phpfreaks.com/topic/101511-help-with-select-command/#findComment-519935 Share on other sites More sharing options...
mcmuney Posted April 17, 2008 Author Share Posted April 17, 2008 There's no error, but it doesn't produce any results. When I remove the "round" portion of the code, the query shows results. Link to comment https://forums.phpfreaks.com/topic/101511-help-with-select-command/#findComment-519993 Share on other sites More sharing options...
psychowolvesbane Posted April 17, 2008 Share Posted April 17, 2008 I'm not too sure but do you need to have the brackets around the whole "Order By (round((sum_/count_),2))" part? When you just have no brackets with normal ORDER BY fields scripts. Link to comment https://forums.phpfreaks.com/topic/101511-help-with-select-command/#findComment-519994 Share on other sites More sharing options...
mcmuney Posted April 18, 2008 Author Share Posted April 18, 2008 Tried nearly everything that I could think of, it just doesn't seem to be doing the math "A/B". Link to comment https://forums.phpfreaks.com/topic/101511-help-with-select-command/#findComment-520021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.