doushi1974 2013-08-04 18:27
浏览 11
已采纳

按最高值对列进行排序

I need to sum columns and sort them highest to lowest.

This is what I've tried!

$sth = $db->prepare("SELECT sum(A), sum(S), sum(D), sum(F) FROM XXX order by A, S, D, F DESC");
$sth->execute();

$result = $sth->fetch(PDO::FETCH_ASSOC);

This is what the output looks like:

Array ( [sum(A)] => 38 [sum(S)] => 194 [sum(D)] => 40 [sum(F)] => 164 )
  • 写回答

3条回答 默认 最新

  • duanlan3598 2013-08-04 18:31
    关注

    Why not just use rsort(), in php when the results are returned??

    sort() will to lowest to highest, rsort() will do highest to lowest

    rsort($result);
    print_r($result);
    

    Or to keep the associative features of your array, use asort() (low->high), or arsort(); (high->low)

    arsort($result);
    print_r($result);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn