gpt4 book ai didi

mysql - 有人可以帮我找到问题吗? MySQL/子查询

转载 作者:行者123 更新时间:2023-11-29 15:11:16 25 4
gpt4 key购买 nike

我正在尝试插入由用户点导出的“排名”数据。但是每次我使用子查询插入时,它都会返回NULL值。

create table rank_info(
rank_num INT,
min_point INT,
max_point INT,
primary key(rank_num)
);



create table user(
num INT,
name varchar(45),
point INT,
user_rank INT,
primary key(num),
foreign key(user_rank) references rank_info(rank_num)
);

insert into rank_info values (1, 200, 300);
insert into rank_info values (2, 100, 199);
insert into rank_info values (3, 0, 99);
insert into user values(1, 'jake', 150,
(select rank_num from (
(select rank_num from rank_info, user
where user.point between min_point and max_point))
a ));

<< 这就是我被困住的地方。永远谢谢你。

最佳答案

您应该使用带有 join 的更新(而不是插入)

 update  user  u
inner join rank_info r on u.point between r.min_point and r.max_point
set u.rank_num = = r.rank_num

关于mysql - 有人可以帮我找到问题吗? MySQL/子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60040965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com