Showing posts with label Zero. Show all posts
Showing posts with label Zero. Show all posts

Tuesday 14 June 2016

Sort by price, quantity low-> high. 0 price get last


Here is the my result query. I have required result of sort by price low-> high but it gives me a result that starts with records that have the price 0. This is correct, but I don't want the 0 price records first. Result should start with prices greater than 0 and 0 price records should be displayed last.
Please help me to solve my this query.

For example, the result should start start with price 12.00, 15.00..... 0, 0, 0

SELECT
    product_id, quantity, price,
    CASE price WHEN 0
        THEN 1
        ELSE 0
    END
    as is_price_zero
FROM
    product
ORDER BY
    is_price_zero ASC,
    price ASC