Irfan Irfan - 1 month ago 9
MySQL Question

Query for products offer in mysql?

I'm using

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


where
productinfo
is table, And i display products on the basis of
productPrice
and
productSaleprice
.

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

$diff=$productPrice-$productSaleprice;
$result=($diff)/($productPrice/100);


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

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