jeudi 5 septembre 2019

Alias creating problem while using CASE query

I am using CASE to match certain conditions records in table, now in where clause I need to use alias of CASES but it is not allowing, the error shows unknown column monthly_price.

Here is my query:

select 
            (CASE when price > 0 and price < 2000 then (price * 0.05)
            when price > 0 and price <5000 then (price * 1)
            else price
            end)
         as monthly_price,price from qd_posts
         WHERE qd_posts.monthly_price >=0 AND qd_posts.monthly_price <= 5000

I am not sure why it is not allowing.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire