gpt4 book ai didi

mysql - 具有 3 个对同一字段的引用的多列查询结果

转载 作者:行者123 更新时间:2023-11-30 23:26:00 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
sql query joining two columns with one

所以我在 MySQL 中正确查询时遇到了一些问题。

这是我现在正在使用的表格

DROP TABLE IF EXISTS `qualifications`;
CREATE TABLE `qualifications`(
`activity` int NOT NULL,
`group` int NOT NULL,
`tournament` int NOT NULL,
`judge_1` int NOT NULL,
`grade_1` int NOT NULL,
`judge_2` int NOT NULL,
`grade_2` int NOT NULL,
`judge_3` int NOT NULL,
`grade_3` int NOT NULL,
PRIMARY KEY(`activity`,`group`),
FOREIGN KEY(`activity`) REFERENCES `activities`(`id`),
FOREIGN KEY(`group`) REFERENCES `groups`(`id`),
FOREIGN KEY(`judge_1`) REFERENCES `judges`(`id`),
FOREIGN KEY(`judge_2`) REFERENCES `judges`(`id`),
FOREIGN KEY(`judge_3`) REFERENCES `judges`(`id`),
FOREIGN KEY(`tournament`) REFERENCES `tournaments`(`id`)
)ENGINE=InnoDB, DEFAULT CHARSET=utf8;

我想要的是获取事件名称、小组名称、锦标赛名称以及所有 3 位评委的姓名和成绩。这是我到目前为止的查询:

select a.name as Game, t.name as Tornament, g.name as "Group", j.name as Judge1, j.name as Judge2, (q.grade_1+q.grade_2+q.grade_3) as Grades from activities a, groups g, judges j, tournaments t, qualifications c where
a.id = q.activity and t.id = q.tournament and g.id = q.group and g.id = 2;

当然,除了法官的名字,这工作正常......我怎么能在一个结果中得到 3 个法官的名字?

提前谢谢大家,如果我不能很好地解释我自己,我深表歉意。

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