Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


  Performparam.performparam_Name,studfeedback.studfeedback_Rating,        SUM(studfeedback.studfeedback_Rating) AS total, 
COUNT(studfeedback.studfeedback_Rating) AS totastudents,   **SUM(studfeedback.studfeedback_Rating)/ COUNT(studfeedback.studfeedback_Rating)   AS Mean_Q1**, 
 empsubject.empsubject_Emp_Code,empsubject.empsubject_Emp_Name, dept.dept_Name,
 LEFT JOIN dept ON studfeedback.studfeedback_Dept_Id_Fk = dept.dept_Id
 LEFT JOIN empSubject ON empSubject.empSubject_Id = 
     Performparam ON studfeedback.studfeedback_Performparam_Id_Fk= 

 GROUP BY performparam.performparam_Name,   empsubject.empsubject_Emp_Code
 ORDER BY Performparam.Performparam_Order


As seen by Bold Text I am Trying to Get The Mean Of Ratings Provided By Students Using Agg. Functions , Since Mean_Q1 is not a pre defined column , I am having Hard time converting Rows Into Columns.?

The Over All Goal Of the Query is to Calculate Rating Of each staff Provided By Students based On certain number of questions (10 in this case ) So ten rows are coming fine , where each row indicating Mean Of the Rating , SO I want These Mean separately For Reporting Purpose .

Result :

   total_students    Mean_Q1    
    142          7.147887324    
    142          7.338028169    
142          6.112676056    
142          7.042253521    
142          8.352112676    
142          6.964788732    
142          6.922535211    
142          7.478873239    
142          7 .415492958   
142          8.084507042    

I'll Further EDIT this Question For more clarifications.

share|improve this question
What values are you trying to turn into columns? It is not clear what you want to PIVOT. – bluefeet Dec 3 '12 at 12:44
I'm not sure If I understood your question correctly but you want to get rating of each staff member as one separate row with columns for rating on each criteria (question)? – Dec 3 '12 at 13:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.