如何根据SQLITE中表b的值更新表的一列?

时间:2019-01-16 11:11:36

标签: sqlite

我有两个桌子。表a和表b。它们与a.productID = b.productID连接。我的问题是如果表b.culumn包含特定值,如何更新表a.column。我搜索了这个问题,但没有任何帮助,所以我问你。

我的代码(可能应该是这样的):

SELECT Cars a
LEFT JOIN Season b ON a.productID = b.productID
SET a.type = "winter" CASE b.month < 3 OR b.month > 11  

这对我不起作用。

2 个答案:

答案 0 :(得分:2)

只需猜测您想做什么:

update Cars
set Cars.type = 'winter'
where exists (
  select 1 from b where 
  b.productID = Cars.productID and (b.month < 3 OR b.month > 11)
)

答案 1 :(得分:0)

使用具有相关子查询的更新:

UPDATE Cars a
SET a.type = 'winter'
WHERE
    (SELECT b.month FROM Season b WHERE a.productID = b.productID) < 3 OR
    (SELECT b.month FROM Season b WHERE a.productID = b.productID) > 11;
相关问题