简体   繁体   English

如何让我的 UPDATE 语句在 ctree 上运行?

[英]How do I get my UPDATE statement to function on ctree?

So I am writing a script that both inserts and updates based on a certain condition.所以我正在编写一个基于特定条件插入和更新的脚本。 I have the insert statement finished but having a hard time trying get my UPDATE statement to work in CTREEACE DATABASE script section.我已经完成了插入语句,但很难让我的 UPDATE 语句在 CTREEACE DATABASE 脚本部分工作。 If there is anybody familiar with ctree that could help please take a look and see if there is something wrong with my syntax.如果有人熟悉 ctree 可以提供帮助,请查看我的语法是否有问题。

UPDATE act
SET tbl71.address = act.address
FROM act
INNER JOIN tbl71 ON act.address = tbl71.address
WHERE dates = '7/31/2018'

act view 
----------
trackingid(varchar)
delivery_time(varchar)
state(varchar)
address(varchar)                             
city(varcahr)
zipcode(varchar)
dates(varchar)

tbl71 view 
----------
trackingid(varchar)
delivery_time(varchar)
state(varchar)
address(varchar)
city(varcahr)
zipcode(varchar)
dates(varchar)

If an address exists based upon dates within the act view from tbl71 then update all columns in act from tbl71如果根据 tbl71 的行为视图中的日期存在地址,则更新来自 tbl71 的行为中的所有列

At the beginning check these 8 rules:一开始检查这8条规则:

  1. The view is defined based on one and only one table视图是基于一张且只有一张表定义的
  2. The view must include the PRIMARY KEY of the table based upon which the view has been created视图必须包含创建视图所依据的表的 PRIMARY KEY
  3. The view should not have any field made out of aggregate functions视图不应有任何由聚合函数组成的字段
  4. The view must not have any DISTINCT clause in its definition视图的定义中不得有任何 DISTINCT 子句
  5. The view must not have any GROUP BY or HAVING clause in its definition视图的定义中不得包含任何 GROUP BY 或 HAVING 子句
  6. The view must not have any SUBQUERIES in its definitions视图的定义中不得包含任何子查询
  7. If the view you want to update is based upon another view, the later should be updatable.如果您要更新的视图基于另一个视图,则后者应该是可更新的。 Any of the selected output fields (of the view) must not use constants, strings or value expressions任何选定的输出字段(视图的)不得使用常量、字符串或值表达式

Next one problem is that idk why are you trying to update column from another view (tbl71) using from (act),but it's up to you.下一个问题是 idk 为什么要尝试使用from (act) 从另一个视图(tbl71) 更新列,但这取决于您。

If this example doesn't work it's ok:如果这个例子不起作用,那没关系:

UPDATE act
SET act.address = tbl71 .address
FROM act
INNER JOIN tbl71 ON act.address = tbl71.address
WHERE dates = '7/31/2018'

Try to see the result of this simple query to see that union or join works:尝试查看这个简单查询的结果以查看联合或连接是否有效:

    SELECT *
    FROM act
    INNER JOIN tbl71 ON act.address = tbl71.address

After this try to add *"Where":在此之后尝试添加 *"Where":

SELECT *
FROM act
INNER JOIN tbl71 ON act.address = tbl71.address
WHERE dates = '7/31/2018'

And finally try to get in update.最后尝试更新。 The easiest way can be to recreate a views (make a 1 view instead of 2, that will get the final data that you need.)最简单的方法是重新创建视图(创建 1 个视图而不是 2 个,这将获得您需要的最终数据。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM