mysql 版本
gg@debian:~/sq$ mysql --version
mysql Ver 8.0.18 for Linux on x86_64 (MySQL Community Server - GPL)
新建用户
create user 用户名@允许该用户登录的IP identified with mysql_native_password by “密码”;
create user gg@localhost identified with mysql_native_password by "gg";
给用户授权数据库权限
grant all on test.* to gg@localhost with grant option;
gg ->用户
test.* ->test数据库所有表
all ->所有权限
update 某一记录某个字段的值赋值到另一条记录 除了使用联合也可以使用 select 子句
在 update 中使用 select 子句结果
update Product set sale_price=(select x.sale_price+9000 from Product as x where x.product_id=0002) where product_id=0001;
在 MySql 中报错 没有具体研究为什么不行 在 MySql 中 可以再 select 一次避免这个报错
ER_UPDATE_TABLE_USED: You can’t specify target table ‘Product’ for update in FROM clause
update Product
set sale_price=(select y.sale_price+3000 from (select x.sale_price from Product as x where x.product_id=0002) as y)
where product_id=0001;