如果预订表格填写完毕,我目前可以提取准确的数字。然而,由于业务场景,“DateIN”将在稍后日期完成。如果预订没有完成,那么我的数据就会完全失效。
在这种情况下,该字段默认为 1970/1/1,直至更新。我想做的是以某种方式忽略这些字段,有人建议我将字段更改为 null 直到稍后更新可能会解决我的问题,但我不知道如何执行此操作。
代码如下。
SELECT
SUM((MatCost+TimeCost)+((DateIn-DateOut)*RentPD+((DateIn-DateDue)*10))-DepReq) AS TotalDue,
employee.Fname, employee.Sname
FROM booking
INNER JOIN customer ON booking.CustID = customer.CustID
INNER JOIN costume ON booking.CostID = costume.CostID
INNER JOIN employee ON booking.EmpID = employee.EmpID
GROUP BY employee.Fname, employee.Sname
ORDER BY TotalDue DESC
最佳答案
您可以对 DateIn 字段运行更新查询,并在存在“1970/1/1”的地方将其设置为 null 即。
update booking
set DateIn = null
where DateIn = '19700101'
然后在上面的查询中
SELECT
SUM((MatCost+TimeCost)+((DateIn-DateOut)*RentPD+((DateIn-DateDue)*10))-DepReq) AS TotalDue,
employee.Fname, employee.Sname
FROM booking
INNER JOIN customer ON (booking.CustID = customer.CustID AND booking.DateIn is not null)
INNER JOIN costume ON booking.CostID = costume.CostID
INNER JOIN employee ON booking.EmpID = employee.EmpID
GROUP BY employee.Fname, employee.Sname
ORDER BY TotalDue DESC
我希望这会有所帮助..
关于mysql - 在 MySQL 中创建查询返回疯狂的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27271223/