mysql查询更改

时间:2011-03-07 12:06:07

标签: mysql

编辑:在此查询中完成一个小的修改。 那就是我需要以下列格式显示结果:

1。其中totalDealsBought小于maxBuy应显示为FIRST。

如何做到这一点?

SELECT d.id, d.dealTitle, d.expiryDate, d.dealMainImage, d.actualPrice, 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

enter image description here

提前致谢。

2 个答案:

答案 0 :(得分:0)

... AND sc.paymentStatus = 'paid'
    GROUP BY d.id
    ORDER BY totalDealsBought, maxBuy 

答案 1 :(得分:0)

... GROUP BY d.id 
    ORDER BY (totalDealsBought < d.maxBuy) DESC