gpt4 book ai didi

mysql - 用户表在多表上显示 NULL 数据

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

我正在练习mysql上的多表。创建表时,“用户表”上出现空数据。用户表应包含 user_id(auto_increment)。 user_name 应出现在来自订单表的 user_info 表中。

create table orders(
primary key (order_id),
order_id int(11) not null auto_increment,
order_no varchar(100) default null,
user_name varchar(100) not null,
product_name varchar(100) not null,
order_status enum('CART', 'DRAFT', 'NEW', 'IN PROCESS', ' COMPLETED', 'FAILED' ) DEFAULT 'CART',
carete_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '注册时间');

最佳答案

没有任何代码可以将任何内容插入到“users”表中,所以我不确定为什么您希望它包含任何数据?

你的线路

select distinct user_name from orders;

在用户表的创建语句之后,将仅在屏幕上显示一个列表。也许你想写

insert into users (user_name) select distinct user_name  from orders;

这实际上会向用户表添加一些行。

关于mysql - 用户表在多表上显示 NULL 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53053889/

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