时间:2021-07-01 10:21:17 帮助过:25人阅读
select t.username,sum(t.money) as sum1
from table t
where t.type=1
group by t.username
order by sum1 desc
select sum(b.money) from b left join a.userid=b.userid where b.type=1 order by sum(b.money) desc
select username,sum(money) as total from 消费记录表B where type=1 group by username order by total desc
$strsql="select * from B where type=1"; $result=mysql_db_query($mysql_database, $strsql, $conn); mysql_data_seek($result, 0); $re = array();while ($row=mysql_fetch_row($result)) { isset($row['userid']) && $re[$row['userid']] += $row['money']; isset($row['userid']) || $re[$row['userid']] = $row['money'];} foreach($re as $key=>$value) {echo $value['username'].' '.$value['money'];}// 释放资源 mysql_free_result($result); // 关闭连接 mysql_close($conn);
select username,sum(money) as total from 消费记录表B where type=1 group by userid order by total desc;