Jump to content

Sort by SUM value?


Stuve

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.