[英]Subtract two fields in two different tables to insert different into a third field in second table
We have a db that was converted by a third party from cube cart to prestashop. 我们有一个数据库,该数据库由第三方从多维数据集购物车转换为prestashop。 Mostly things went fine but recently found a couple thousand products that lack a discount reduction value.
大多数情况下情况都很好,但最近发现有成千上万的商品没有折扣降低值。
I have found bits and pieces on how to do what we need but I just need help. 我发现了如何做我们需要做的零散的工作,但我只需要帮助。 This is my first foray into sql/php so bear with me and dont laugh too much.
这是我第一次尝试sql / php,所以请多多包涵,不要笑太多。
After research I learned enough to do it within the same table but this playing with values from two different tables my brain goes "Im outta here." 经过研究,我学到了足够的知识,可以在同一个表中执行此操作,但是这与两个不同表中的值一起玩时,我的大脑变得“我不在这里”。
SELECT *, (price - discount) AS Sum FROM Table1
I found some examples but nothing crosses over close enough to my needs to work or my syntax is messing things up. 我找到了一些示例,但是没有什么东西可以满足我的工作需要,或者我的语法搞砸了。
Even a nudge in the right direction would mean a lot. 即使是朝着正确的方向轻推也将有很多意义。
select b.*, (b.price - a.discount) as sum
from table2 b
left join table1 a on b.product_id = a.product_id
So if I understand this correctly table1 has product Id, base price, and table2 has discount? 因此,如果我正确理解表1的产品ID,基本价格以及表2的折扣?
It looks like you want to take table 2 and just add a column that has price after discount on every row? 看来您想使用表2,仅添加一列,每行都有折后价格?
Let me know and I can try and guide you further.... 让我知道,我可以尝试进一步指导您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.