选择查询语句

时间:2012-03-06 22:25:04

标签: mysql sql

Hy all ..我有一个关于查询的问题。我有3个表,我想要做的是将它们组合起来以获得好看的结果。所以我有以下3个表:

  personal
- cod_numeric_personal
- nume


  Raspunsuri
- raspuns
- cod_numeric_personal
- data_raspuns
- id_intrebare

  Intrebari
-intrebari
-id_intrebare

我做了这个查询:

SELECT personal.nume, Raspunsuri.raspuns, Intrebari.intrebari
FROM personal
INNER JOIN Raspunsuri ON personal.cod_numeric_personal = Raspunsuri.cod_numeric_personal
INNER JOIN Intrebari ON Raspunsuri.id_intrebare = Intrebari.id_intrebare

这会显示每个答案的用户名,答案和问题。我想要的是只提出一次名称,并将每个“intrebare”的问题提到列的名称和每一列都有答案。所以喜欢..Intrebare1 ... Answer1 ...但是Intrebare1是列的名称。

1 个答案:

答案 0 :(得分:0)

SELECT personal.nume, Raspunsuri.raspuns, Intrebari.intrebari AS Answer
FROM personal
INNER JOIN Raspunsuri ON personal.cod_numeric_personal = Raspunsuri.cod_numeric_personal
INNER JOIN Intrebari ON Raspunsuri.id_intrebare = Intrebari.id_intrebare
Group By nume