按最大值对查询结果进行排序(结果从最大值到最小值)

时间:2019-04-25 15:44:40

标签: php mysql

我有一张表格(tuition_fees),由id,uni,本科生和研究生组成。该查询返回本科和研究生学习的学费以及总金额(本科和研究生)的结果。如何将这些结果从总和的最大值到最小值进行排序。

<?php
$connect = mysqli_connect('localhost', 'root', '', 'test')or die ( mysqli_error($connect) ); 
$sSQL= 'SET CHARACTER SET utf8'; 
mysqli_query($connect,$sSQL) 
or die ('Can\'t charset in DataBase'); 
$output = '';
$return = '';
$search = mysqli_real_escape_string($connect, $_POST["query"]);
 $query = "select t.uni, 
(select  undergraduate from tuition_fees where `uni` = t.uni) as 'undergraduate1',
(select  postgraduate from tuition_fees where `uni` = t.uni) as 'postgraduate2'
from tuition_fees t group by t.uni
";


$result = mysqli_query($connect, $query);

$i=1;
 while($row = mysqli_fetch_array($result))

{

$return .='<tr>';

$return .=  '<td style="width: 4%; background:#F0F8FF; color:black;" align="center">' . $i . '</td>'; 
$return .='<td style="width: 15%; background:#F0F8FF; color:black;" align="right">'.$row['uni'].'</td>';
$return .='<td style="width: 14%; background:#F0F8FF; color:black;" align="center">'.$row['undergraduate1'].'</td>';
$return .='<td style="width: 14%; background:#F0F8FF; color:black;" align="center">'.$row['postgraduate2'].'</td>';

$totalsum1=$row['undergraduate1']+$row['postgraduate2'];
$return .='<td style="width: 14%; background:#F0F8FF; color:#00008B;" align="center">'.$totalsum1.'</td>';
$return .='</tr>';
$i++;
}
echo "<br/><div style ='font:18px Times New Roman,sans-serif;'> $return</div>";   

?>

1 个答案:

答案 0 :(得分:0)

不是答案;评论太久了...

对于它的价值,我发现它更易于阅读...

tabBarOptions