我有 6 个表:3 个用于有关动漫/漫画/ova/whatever 的一般数据,3 个用于它们的流派,这是一对一的关系
anime: manga: ova:
aid | data | ... | mid | data | ... | oid | data | ... |
----+------+-----+ ----+------+-----+ ----+------+-----+
1 | .... | ... | 1 | .... | ... | 1 | .... | ... |
2 | .... | ... | 2 | .... | ... | 2 | .... | ... |
3 | .... | ... | 3 | .... | ... | 3 | .... | ... |
4 | .... | ... | 4 | .... | ... | 4 | .... | ... |
anime_genre: manga_genre: ova_genre:
aid | genre mid | name oid | genre
----+-------- ----+---------- ----+--------
1 | Ecchi 1 | Drama 1 | Action
1 | Action 2 | Ecchi 2 | Action
2 | Action 3 | Fighting 3 | Drama
3 | Drama 4 | Action 4 | Ecchi
4 | Action
每当有人搜索流派以在一个查询中获取所有信息时,我都会尝试对结果进行分组
情况1:
result on genre = Action:
genre | ids
--------+---------------------------------------------
Action | 1:anime 2:anime 4:anime 4:manga 1:ova 2:ova
result on genre = Ecchi:
genre | ids
--------+-------------------------------
Ecchi | 1:anime 4:anime 2:manga 4:ova
案例2(优选):
result on genre = Action:
genre | id | common data | common data | common data
--------+---------+-------------+-------------+-------------
Action | 1:anime | ... | ... | ...
Action | 2:anime | ... | ... | ...
Action | 4:anime | ... | ... | ...
Action | 4:manga | ... | ... | ...
Action | 1:ova | ... | ... | ...
Action | 2:ova | ... | ... | ...
result on genre = Ecchi:
genre | id | common data | common data | common data
-------+---------+-------------+-------------+-------------
Ecchi | 1:anime | ... | ... | ...
Ecchi | 4:anime | ... | ... | ...
Ecchi | 2:manga | ... | ... | ...
Ecchi | 4:ova | ... | ... | ...
我整天都在打我的头,我只能得到一张桌子的预期结果。我无法设法获得所有三合一查询的结果。
有任何想法吗?有人可以指出我正确的方向吗?(数据表有一些不常见的列,但我并不关心我是否得到空值,因为我在 js 中解析结果)