Stuve Posted October 16, 2007 Share Posted October 16, 2007 Why can't I order by SUM value? I get this error "Invalid use of group function". $sql="SELECT *, SUM(sm), SUM(gm), SUM(a), SUM(tp), SUM(um) FROM spelarstat WHERE lagid = '".$_GET['id']."' GROUP BY spelarid ORDER BY SUM(tp) DESC, SUM(gm) DESC, SUM(a) DESC, SUM(um)"; Help me please!! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 16, 2007 Share Posted October 16, 2007 Try giving each SUM a name: <?php $sql="SELECT *, SUM(sm) as sum_sm, SUM(gm) as sum_gm, SUM(a) as sum_a, SUM(tp) as sum_tp, SUM(um) as sum_um FROM spelarstat WHERE lagid = '".$_GET['id']."' GROUP BY spelarid ORDER BY sum_tp DESC, sum_gm DESC, sum_a DESC, sum_um"; ?> Ken Quote Link to comment Share on other sites More sharing options...
SammyGunnz Posted October 16, 2007 Share Posted October 16, 2007 . Quote Link to comment Share on other sites More sharing options...
Stuve Posted October 16, 2007 Author Share Posted October 16, 2007 Thanx a lot! Quote Link to comment Share on other sites More sharing options...
Stuve Posted October 16, 2007 Author Share Posted October 16, 2007 Btw.. is it possible to get the MAX value from a SUM value? Something like this: SELECT MAX(SUM(a)) FROM stat GROUP BY id Quote Link to comment Share on other sites More sharing options...
teng84 Posted October 16, 2007 Share Posted October 16, 2007 Btw.. is it possible to get the MAX value from a SUM value? Something like this: SELECT MAX(SUM(a)) FROM stat GROUP BY id before asking like this you should try it first ??? any way it will work Quote Link to comment Share on other sites More sharing options...
Stuve Posted October 17, 2007 Author Share Posted October 17, 2007 No, it's not working.. I get "Invalid use of group function"... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.