1

I have a doubt similar to the question posted in the link SQL - columns for different categories. I have student table with Student Name, Midterm Grade and Final Grade as dipicted in GradeTable below.

StName  MidTermGrade    FinalGrade
St1         1               1
St2         2               1
St3         2               3
St4         1               3
St5         1               1
St6         2               3
St7         2               2
St8         1               1
St9         2               2
St10        2               3
St11        3               1
St12        2               1
St13        3               3
St14        3               2
St15        1               2

This data needs to be categorised using SQL query to generate the output so that all the grading and Student Names fall in one query output which i can paste in word/excel and provide it as report.

FinalGrade  MidTermGrade1   MidTermGrade2   MidTermGrade3
   1        St1             St2             St11
   1        St5             St12    
   1        St8     
   2        St15            St7             St14
   2                        St9 
   3        St4             St3             St13
   3        St6 
   3                        St10    

Please help and advise if this can be achieved.

Community
  • 1
  • 1
Raghu
  • 105
  • 1
  • 5
  • 1
    What kind of database are you using? mysql, MSSQL..? – barsju May 06 '12 at 17:04
  • I don't get it. The column says midtermgrade1, but it seems to contain a student name. Can you better describe what you want? – Gordon Linoff May 07 '12 at 02:37
  • The basic idea is the row and column grouping will happen based on the grade obtained by the student. So the end result would be a matrix of Final Grading(Row) V/s Mid Term Grading(Column) with Student Names placed in the respective cells. I am not sure, if such kind of grouping can be done in SQL. Please advise. – Raghu May 07 '12 at 07:49

1 Answers1

0

Don't think it is easy/possibly to get what you need, but maybe this is good enough:

select FinalGrade, MidtermGrade, group_concat(StName) from GradeTable group by FinalGrade, MidtermGrade;

Then you can easily do the rest with code..?

barsju
  • 4,408
  • 1
  • 19
  • 24