我有一个名为physical_exam_tool_and_body_parts的表,其中包含:
id physical_exam_tool_id body_part_id
body_parts表格包含:name_tid
physical_exam_tools表格包含:name_tid
翻译表如下:
id lang text
我正在尝试查询:
SELECT physical_exam_tool_text,
body_part_text
FROM physical_exam_tool_and_body_parts
WHERE translation.lang = 'fr'
我想要lang'fr'的身体部位和身体检查工具的名称。我怎样才能做到这一点。我是新加入的人。
body_parts和physical_exam_tools表有:
id name_tid
name_tid是转换表中的ID。翻译表有id lang文本。因此,翻译的主键是复合键(id,lang)。
在physical_exam_body_part_and_tool中,id只是body_parts和physical_exam_tools表的id(外键)。
答案 0 :(得分:0)
像这样。
SELECT PHYSICAL_EXAM_TOOL_TEXT,
BODY_PART_TEXT
FROM PHYSICAL_EXAM_TOOL_AND_BODY_PARTS A
INNER JOIN BODY_PARTS B
ON A.BODY_PART_ID = B.ID
INNER JOIN TRANSLATION C
ON C.ID = B.NAME_TID
WHERE C.LANG = 'FR'
答案 1 :(得分:0)
两次加入翻译表,其中lang ='fr'。
SELECT t.[text] AS [ExamTool], t2.[text] AS [BodyPart]
FROM physical_exam_tool_and_body_parts as p
inner join physical_exam_tool as pet
on p.physical_exam_tool_id = pet.physical_exam_tool_id
and t.lang = 'fr'
inner join translation as t
on pet.name_tid = t.id
inner join body_parts as b
on p.body_part_id = b.body_part_id
inner join translation as t2
on b.name_tid = t2.id
and t2.lang = 'fr'