英文:
MULTIPLY EACH ROW VALUES WITH DIFFERENT VALUES
问题
大家好,
在这里,我试图将每行乘以不同的值相乘。
例如..,
我有3列,
`
customer_id(int) , product_name(varchar) , price(int)`
1 LV 5
2 MK 15
3 YSL 16
我想要将Product_name = LV, MK的每个产品乘以10,Product_name = YSL的产品乘以20。
请问我如何实现这个目标..,
您的帮助将不胜感激
英文:
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)`
1 LV 5
2 MK 15
3 YSL 16
I would like to multiply each Product_name = LV, MK by 10 and Product_name = YSL by 20.
Could you please tell me how can I achieve this..,
Your help could be appreciated
答案1
得分: 2
你可以通过在SQL中直接使用CASE语句来完成。
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;
英文:
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;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论