1

テーブルが3つあり、結合したいと思います。

このフィドルを確認してください:http ://sqlfiddle.com/#!2/20410/2

列:数字の代わりにsegunda、terca、quarta、quinta、sexta...「materias」テーブルの名前が必要です。しかし、私は同じテーブル「材料」からすべてのIDをチェックします

それは可能ですか?誰かが私を助けることができますか?

4

2 に答える 2

1

次のクエリを試してください。

SELECT
h.id_classe,
h.id_aula,
s.serie,
m1.materia as segunda,
m2.materia as terca,
m3.materia as quarta,
m4.materia as quinta,
m5.materia as sexta
FROM horario_de_aulas h
INNER JOIN materias as m1 on h.segunda = m1.id_materia
INNER JOIN materias as m2 on h.terca = m2.id_materia
INNER JOIN materias as m3 on h.quarta = m3.id_materia
INNER JOIN materias as m4 on h.quinta = m4.id_materia
INNER JOIN materias as m5 on h.sexta = m5.id_materia
INNER JOIN series s ON h.classe = s.id_serie = 1
LIMIT 4
于 2012-06-01T06:41:52.213 に答える
1

これは、内部結合とサブクエリを使用する2つの方法で実行できます。

内部結合の使用:

SELECT
h.id_classe,
h.id_aula,
s.serie,
m1.materia as segunda,
m2.materia as terca,
m3.materia as quarta,
m4.materia as quinta,
m5.materia as sexta
FROM horario_de_aulas h
INNER JOIN materias as m1 on h.segunda = m1.id_materia
INNER JOIN materias as m2 on h.terca = m2.id_materia
INNER JOIN materias as m3 on h.quarta = m3.id_materia
INNER JOIN materias as m4 on h.quinta = m4.id_materia
INNER JOIN materias as m5 on h.sexta = m5.id_materia
INNER JOIN series s ON h.classe = s.id_serie = 1
LIMIT 4

サブクエリの使用

SELECT
h.id_classe,
h.id_aula,
s.serie,
(select materia from materias where id_materia=h.segunda) as segunda,
(select materia from materias where id_materia=h.terca) as terca,
(select materia from materias where id_materia=h.quarta) as quarta,
(select materia from materias where id_materia=h.quinta) as quinta,
(select materia from materias where id_materia=h.sexta) as sexta
FROM horario_de_aulas h
INNER JOIN materias m
INNER JOIN series s ON h.classe = s.id_serie = 1
LIMIT 4
于 2012-06-01T06:45:26.650 に答える