Irfan Irfan - 1 year ago 90
MySQL Question

Query for products offer in mysql?

I'm using

productinfo (`productId`, `productName`, `productPrice`, `productSaleprice`, `productImage`, `productLink`, `productColor`, `productSize`, `categoryId`, `sourceProductId`, `sourceId`)

is table, And i display products on the basis of

At this moment I fetch all results and calculate everything in PHP like this:


My question is, is it possible to calculate the same things in MySQl without using PHP?

The result should be displayed in DESC Order

Answer Source

I think below SQL useful to you.

    select `productId`, `productName`, productPrice, productPrice, productPrice-productSaleprice as diff , 
         (productPrice-productSaleprice)/(productPrice/100) as result
    from productinfo
where category= 5
    order by result desc;

Thank you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download