Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在where语句中使用子查询进行SQL更新错误_Mysql_Sql_Mysql Workbench - Fatal编程技术网

Mysql 在where语句中使用子查询进行SQL更新错误

Mysql 在where语句中使用子查询进行SQL更新错误,mysql,sql,mysql-workbench,Mysql,Sql,Mysql Workbench,我试图通过引用国家/地区表更新位于“美国”的所有客户的电子邮件,但我不断收到一个错误:错误代码:1054。“全部/任何子查询”中的未知列“国家” Update Customer Set email = concat(substr(first_name,1,1), last_name,'@sakilacustomer.com.us') where country in(Select country From customer join address using(address_id) join

我试图通过引用国家/地区表更新位于“美国”的所有客户的电子邮件,但我不断收到一个错误:错误代码:1054。“全部/任何子查询”中的未知列“国家”

Update Customer
Set email = concat(substr(first_name,1,1), last_name,'@sakilacustomer.com.us')
where country in(Select country From customer
join address using(address_id)
join city using(city_id)
join country using(country_id)
Group by country
Having country = 'United States');
也试过

Update Customer
Set email = concat(substr(first_name,1,1), last_name, '@sakilacustomer.com.us')
where country in(Select country From country where country = 'United States');
我提供了EER图的图像,可以作为参考


这似乎很复杂。这个怎么样

Update Customer c join
       address a
       using (address_id) join
       city ci
       using (city_id) join
       country co
       using (country_id)
    set c.email = concat(left(c.first_name, 1), clast_name, '@sakilacustomer.com.us')
where co.country = 'United States';

不知何故,我认为您的查询存在的问题是
customer
没有
country
,因此错误是
中的
国家,而不是子查询中的国家。不过,错误消息本身相当混乱。

请尝试以下操作:

 Update a
 set a.email = concat(substr(first_name,1,1), last_name,'@sakilacustomer.com.us')
 from customer a join 
(select * from  customer a
join address b on a.address_id=b.address_id
join city c on a.city_id=c.city_id
join country d on a.country_id=d.country_id 
where country='united states'
 ) b 
 on a.customer_id=b.customer_id

是的,谢谢你,这也是我困惑的地方。。。感谢您的回复,当我使用别名更新后的联接时,它确实起了作用。如果您正在更新联接,则“Set”之后不能有“From”语句。如果您正在更新联接,则应该能够-您在sql server中工作吗?@DanielMarcus语法是
update join()Set。。。其中…
。在SQL中不能重新排列子句的顺序。
update Customer
set email = concat(substr(first_name,1,1), last_name, '@sakilacustomer.com.us')
where customer_id in (
    select customer_id
    from customer join address using(address_id)
         join city using(city_id)
         join country using(country_id)
    where country = 'United States'
);