Here is the query which needs to be altered. I have attached the output of the screen. Here i need only the results where maxBuy is less than or equal to totalDealsBought. How should i change in this query for the O/P.
EDIT : ONE more small alter to be done in this query. That is i need to display the result in following format:
1. Where totalDealsBought should be less than maxBuy should display FIRST.
How can this be done?
SELECT d.id, d.dealTitle, d.expiryDate, d.dealMainImage, d.actu开发者_如何转开发alPrice, d.discount, d.offerValue, d.maxBuy, sum( sc.quantity ) AS totalDealsBought
FROM deal AS d
LEFT JOIN shoppingcart AS sc ON sc.dealID = d.id
WHERE CURDATE( ) != d.startDate
AND d.startDate < CURDATE( )
AND d.status = 'Active'
AND d.cities = 'chennai'
AND sc.paymentStatus = 'paid'
GROUP BY d.id
Thanks in advance.
Add the following line
HAVING maxBuy <= totalDealsBought
to the end of the query.
Have you tried with
GROUP BY d.id
HAVING d.maxBuy <= sum(sc.quantity)
精彩评论