Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MULTIPLY EACH ROW VALUES WITH DIFFERENT VALUES

Hello everyone,

Here I am trying to do the multiplication of reach row multiplied by different values.
For example..,
I have 3 columns with customer_id(int), product_name(varchar) , price(int)

Now, In the column of Product_name = LV, MK, Price column should be multiplied by 10 (Price * 10) and Product_name = YSL product Price column should be multiplied by 20 (Price * 20). Display the results as a new columns as points achieved by each customer.
Could you please tell me how can I achieve this..,

Your help could be appreciated

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can get it done by incorporating a CASE statement directly in the SQL.

SELECT
  customer_id,
  product_name,
  CASE
    WHEN product_name IN ('LV', 'MK') THEN price * 10
    WHEN product_name = 'YSL' THEN price * 20
    ELSE price
  END as adjusted_price
FROM TABLENAME;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading