在SQL中乘以别名

时间:2014-11-30 22:51:52

标签: mysql sql

我有一个任务,我必须使用SQL创建发票,我在第一次尝试内部连接时遇到了问题,并且对所有这些都非常新。当尝试乘以创建的别名时,它会引发错误:

  

#1054 - “字段列表”中的未知列'Bookings.CostumeID'

我不知道我做错了什么,前两个别名到目前为止工作正常。 任何帮助表示赞赏!

代码低于

SELECT booking.BookingID, booking.CustID, Bookings.CostumeID, booking.DateIn,
booking.DateOut, booking.DateDue, customer.Fname, customer.Sname, costume.Description,

DateIn-DateOut AS TotalDays,
DateIn-DateDue AS LateDays,
LateDays*10 AS Penalty

FROM booking
INNER JOIN customer ON booking.CustID = customer.CustID
INNER JOIN costume ON booking.CostID = costume.CostID
where BookingID=1 

1 个答案:

答案 0 :(得分:0)

你错误地使用了Bookings.CostumeID

使用booking.CostumeID代替Bookings.CostumeID

尝试此查询

SELECT booking.BookingID, booking.CustID, booking.CostumeID, booking.DateIn,
booking.DateOut, booking.DateDue, customer.Fname, customer.Sname, costume.Description,

DateIn-DateOut AS TotalDays,
DateIn-DateDue AS LateDays,
(DateIn-DateDue)*10 AS Penalty

FROM booking
INNER JOIN customer ON booking.CustID = customer.CustID
INNER JOIN costume ON booking.CostID = costume.CostID
where BookingID=1