我正在尝试一种方法来将结果从最高数字排序到最低数字。
这里的问题是这些数字来自不同的表,我不知道该怎么做。
请在下面查看.. * 谢谢!
*编辑:
我知道我吮吸编码但仍然:) 我需要的是代替ORDER BY id为$ results(最高数字降低)
我正在使用的当前代码:
$query = "SELECT * FROM tablea WHERE id > 1 AND status = '1' ORDER BY id ASC;";
$result = @mysql_query($query);
for ($i=0; $i < @mysql_num_rows ($result); $i++) {
$row = @mysql_fetch_array($result);
$total = $total + 1;
$results = '';
$noinv = '';
$query2 = "SELECT SUM(number) FROM tableb WHERE id = '$row[id]' AND cur = '1' AND type = '1' AND pos = '1';";
$result2 = @mysql_query($query2);
$row2 = @mysql_fetch_array($result2);
if ($row2['SUM(number)'] == '') {
$row2['SUM(number)'] = '0.00';
}
$query3 = "SELECT SUM(number) FROM tableb WHERE id = '$row[id]' AND cur = '1' AND type = '1' AND pos = '2';";
$result3 = @mysql_query($query3);
$row3 = @mysql_fetch_array($result3);
if ($row3['SUM(number)'] == '') {
$row3['SUM(number)'] = '0.00';
}
$results = $row3['SUM(number)'] - $row2['SUM(number)'];
print $row['id'].' '.$row['status'].' '.$results;
}
答案 0 :(得分:0)
你的问题不清楚,但试着给你一般的答案
选择A.column1,A.column2,A.column3,count(B. *)total
表A,表B
其中A.Id = B.Id
由A.Id分组
按总计desc排序