我知道这是一个愚蠢的问题,但我是 php 新手,所以任何帮助都是有用的。
我有两张桌子,product
并且payment
:
- 产品表有
Id
,Room_Available
,price
, ... - 付款表有
Id
,Product_Id
,Total_Room
, ... - 产品表有很多记录
我期望的是,如果Occupied_Room <= Room_Available
条件失败,则它会提供所有产品记录状态 = 'Y',否则状态 = 'N'。
cms_product.Room_Available
是可用房间总数cms_payment.Total_Room
已订房
查询是:
SELECT SUM(cms_payment.Total_Room) as Occupied_Room,
`cms_product`.`Room_Available` as Available_Room
FROM
(
`cms_product`
LEFT JOIN `cms_payment` on (cms_product.`Id` = cms_payment.`Product_Id`)
)
GROUP BY `cms_product`.`Id`
HAVING Occupied_Room <= Room_Available