MySQL名称而不是ID

时间:2020-08-15 22:05:12

标签: mysql sql

我已经创建了两个表

这是第一张桌子:

create table producers(
id int unsigned not null,
name char(30) not null,
YoE int unsigned not null,
country char(20) not null,
website char(50) not null,
primary key(id))
engine = innodb
default character set utf8 collate utf8_unicode_ci;

这是第二张桌子:

create table games(
id INT unsigned not null,
namegame char(100) not null,
publisher char(60) not null,
producer int unsigned,
type ENUM('action','strategy','party','logic','RPG','arcade','simulation','adventure','sport','racing','fighting'),
price double unsigned not null,
release_date date not null,
metacritics int unsigned not null,
exclusive ENUM('no','Wii','Switch','NDS','PSP','3DS','PS1','PSV','XBOX','GBA','PS2','PS3','PS4','X360','iOS','AND','GCN','PC'),
isSeries ENUM('YES','NO'),
pegi int unsigned not null,
primary key(id),
foreign key(producer) references producers(id))
engine = innodb;

我还添加了值

INSERT INTO producers
VALUES (1,'Ubisoft',1986,'France','www.ubi.com/');
INSERT INTO games
VALUES (1,'Far Cry 5','Ubisoft',1,'action',72.90,'2018-03-27',78,'no','YES',18);

输出,当我使用命令SELECT * FROM games;当然是:

+----+-----------+-----------+----------+--------+
| id | namegame  | publisher | producer | type   |
+----+-----------+-----------+----------+--------+             etc
|  1 | Far Cry 5 | Ubisoft   |        1 | action |
+----+-----------+-----------+----------+--------+

我想创建命令,以便输出看起来像这样。

+----+-----------+-----------+----------+--------+
| id | namegame  | publisher | producer | type   |
+----+-----------+-----------+----------+--------+             etc
|  1 | Far Cry 5 | Ubisoft   |  Ubisoft | action |
+----+-----------+-----------+----------+--------+

我已经用JOIN尝试了一些命令,但是我认为我的知识太少了:( 我想创建命令,以便将生产者的ID更改为该生产者的名称

感谢您帮助我<3

0 个答案:

没有答案