我有以下查询需要用来对表中的列求和,但是我需要通过CONTRACT_PERCENTAGE对它进行多次处理。 CONTRACT_PERCENTAGE存储在与版税不同的表中,称为isrc_codes。两个表共享TRACK_ISRC列。有没有办法从isrc_codes获取CONTRACT_PERCENTAGE并使用它来进行总和计算?
$add = mysqli_query($con,"SELECT sum(DISTRIBUTED_AMOUNT / EXCHANGE_RATE * CONTRACT_PERCENTAGE) FROM royalties WHERE BUNDLE_ARTIST = '".$row['artistname']."'");
while($addamount = mysqli_fetch_array($add)) {
echo '<td>$' . number_format($addamount[0], 2, '.', '') . '</td>';
}
答案 0 :(得分:1)
尝试此查询..
"SELECT sum(r.DISTRIBUTED_AMOUNT / r.EXCHANGE_RATE * i.CONTRACT_PERCENTAGE) FROM royalties r, isrc_codes i WHERE r.TRACK_ISRC = i.TRACK_ISRC AND r.BUNDLE_ARTIST = '".$row['artistname']."'"