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!! Link to comment https://forums.phpfreaks.com/topic/73541-sort-by-sum-value/ 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 Link to comment https://forums.phpfreaks.com/topic/73541-sort-by-sum-value/#findComment-371036 Share on other sites More sharing options...
SammyGunnz Posted October 16, 2007 Share Posted October 16, 2007 . Link to comment https://forums.phpfreaks.com/topic/73541-sort-by-sum-value/#findComment-371038 Share on other sites More sharing options...
Stuve Posted October 16, 2007 Author Share Posted October 16, 2007 Thanx a lot! Link to comment https://forums.phpfreaks.com/topic/73541-sort-by-sum-value/#findComment-371045 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 Link to comment https://forums.phpfreaks.com/topic/73541-sort-by-sum-value/#findComment-371073 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 Link to comment https://forums.phpfreaks.com/topic/73541-sort-by-sum-value/#findComment-371096 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"... Link to comment https://forums.phpfreaks.com/topic/73541-sort-by-sum-value/#findComment-371399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.