【发布时间】:2020-08-10 13:30:15
【问题描述】:
我有以下两张表:
Table 1: Students
name:string,
age:integer,
class:integer,
number_of_allowed_trips:integer
Table 2: Trips
allowed_age:integer,
trip_name:string,
class:integer
我正在尝试根据某些条件为每个学生分配允许的旅行次数。我的查询是:
UPDATE
`mydataset.students` AS s
SET
s.number_of_allowed_trips=(
SELECT
COUNT(*)
FROM
`mydataset.trips` AS t
WHERE
t.r.class= 9)
FROM
`mydataset.trips` AS t
WHERE
r.name = 'Jack'
AND r.class = 9
AND w.class = r.class
但是这个查询不起作用。我在做什么假?我怎样才能让这段代码工作?
【问题讨论】:
-
UPDATE 中允许的位置,请参见此处:stackoverflow.com/a/47373922/14076891
-
是的,这是允许的。但是在您之前的查询中出现了错误。我可以看到你已经修复/编辑了:-)
-
是的 :) 我的意思是,UPDATE 中允许 FROM
-
谢谢。希望查询现在可以正常工作!
-
对我来说它不起作用...没有行受到影响
标签: sql google-bigquery