mardi 20 octobre 2015

Combine fields from multiple rows into one row

I am trying to create a query before exporting data to a CSV File. Each cell must only contain one value, so in this case I won't be able to use GROUP_CONCAT in my query.

Each student has a unique ID. The data is stored at different tables and when I tried using inner joins, there are obviously some duplicated values in some of the rows.

1) Student Table

 studID   | name | teacher | activity
 SQ202      Mich     Lisa    Hearing Test
 FG91A      Lim      Hanson  Behavioural Test

2) Session Table (Each student can have more than one session)

 studID | startTime | endTime  | sessionNo | status
 SQ202      10:00      10:40        1        Completed
 SQ202      13:00      13:50        2        Completed
 FG91A      14:20      15:00        1        Completed

3) Interval Table (Each session has 4 intervals by default)

studID |sessionNum |intervalNo | score  
SQ202       1           1        10/10
SQ202       1           2        7/10
                 .
                 .
                 .

My goal is to retrieve and display all the data tied to the student in a single row.

Here is what I want to achieve :

studID | name | teacher | activity        | startTime | endTime | sessionNo | status    | intervalNo | score | intervalNo | score ... (repeat intervalNo and score)
 SQ202   Mich    Lisa     Hearing Test       10:00      10:40       1         Completed      1         10/10       2        7/10  ...  
 FG91A   Lim     Hanson   Behavioural Test   .......

Aucun commentaire:

Enregistrer un commentaire