我有 mysql 列:
[{"name":"Color","value":"Red (+5$)","price":"+5"}] // options column
并请求:
SELECT C.options, C.qty, P.PRICE
FROM `cart` C
LEFT JOIN `products` P ON C.productid = P.id
WHERE C.userid = '3c9494e7ff22e2a7ac01a3e95fbbc0e4'
但我需要这个:
SELECT C.options, C.qty, (P.PRICE + (substract price +5 from options column))*C.qty
FROM `cart` C
LEFT JOIN `products` P ON C.productid = P.id
WHERE C.userid = '3c9494e7ff22e2a7ac01a3e95fbbc0e4'
上面的请求可以得到吗? 谢谢。
最佳答案
我假设您想总结这些值
尝试一下
SELECT C.options, C.qty, SUM(P.PRICE + c.options) * C.qty
FROM `cart` C
LEFT JOIN `products` P ON C.productid = P.id
WHERE C.userid = '3c9494e7ff22e2a7ac01a3e95fbbc0e4'
GROUP BY c.options,c.qty
如果您需要转换选项列,请这样做
SELECT C.options, C.qty, SUM(P.PRICE + CAST(c.options AS DECIMAL)) * C.qty
FROM `cart` C
LEFT JOIN `products` P ON C.productid = P.id
WHERE C.userid = '3c9494e7ff22e2a7ac01a3e95fbbc0e4'
GROUP BY c.options,c.qty
关于mysql | mysql |具体要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21677581/