可能重複:
sql query joining two columns with one多列查詢結果與3個引用相同的字段
所以我有一些麻煩,在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名法官?
謝謝大家,如果我不能很好地解釋我自己,對不起。