SUM如何ORDER BY

我有用mysql運算欄位t1~30的個別總數
但我要如何讓他以最高到最低的方式排列呢?
標籤:

評論

  • 1. 這是資料庫問題,應該發在資料庫
    2. 你運算的SQL語法先貼上來再問如何改進會比較好

  • $sql = mysql_query(\"SELECT
    SUM(`t1`) as t1,
    SUM(`t2`) as t2,
    SUM(`t3`) as t3,
    SUM(`t4`) as t4,
    SUM(`t5`) as t5,
    SUM(`t6`) as t6,
    SUM(`t7`) as t7,
    SUM(`t8`) as t8,
    SUM(`t9`) as t9,
    SUM(`t10`) as t10,
    SUM(`t11`) as t11,
    SUM(`t12`) as t12,
    SUM(`t13`) as t13,
    SUM(`t14`) as t14,
    SUM(`t15`) as t15,
    SUM(`t16`) as t16,
    SUM(`t17`) as t17,
    SUM(`t18`) as t18,
    SUM(`t19`) as t19,
    SUM(`t20`) as t20,
    SUM(`t21`) as t21,
    SUM(`t22`) as t22,
    SUM(`t23`) as t23,
    SUM(`t24`) as t24,
    SUM(`t25`) as t25,
    SUM(`t26`) as t26,
    SUM(`t27`) as t27,
    SUM(`t28`) as t28,
    SUM(`t29`) as t29,
    SUM(`t30`) as t30
    FROM `goodat`
    \");

    <? while ($row=mysql_fetch_object($sql)){
    foreach($t as $key=>$value){?>
    <? echo $displaygoodat_row[$key]; ?>

    <? echo $row->$key;?>
    <? }}?>
  • 一般不會再 資料庫內做 左右欄位的排序吧...
    所以我會建議你將資料從 資料庫取回來之後
    塞陣列,用陣列直接排序
Sign In or Register to comment.