开发者

mysql query needs to be altered

开发者 https://www.devze.com 2023-02-14 19:05 出处:网络
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

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

mysql query needs to be altered

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消