如何创建子查询以进一步计算DATEDIFF,包括另一列(金额),并为DATEDIFF和X提供输出?
例如。的 ddate*amount/365*0.1 = X
$result = mysqli_query($con,"SELECT *,
DATEDIFF(mdate,pdate)
AS ddate
FROM contacts
WHERE DATEDIFF(mdate,pdate)");
while($row = mysqli_fetch_array($result)) {
echo "<td>" . $row['ddate'] . "</td>";
}
答案 0 :(得分:0)
你可以直接做,不需要子查询:
$result = mysqli_query($con,"SELECT DATEDIFF(mdate,pdate) as NoOfDays,
(DATEDIFF(mdate,pdate) * amount) / 365 * 0.1 as XAmount
FROM contacts
WHERE DATEDIFF(mdate,pdate)>=1");