SQLTeam.com | Weblogs | Forums

Help me with Query


Hi I have below data in one of the table, can any one help in creating the query to meet my requirement.

ResponseId FormSectionId	 SelectedValueId	Rating ManagementInfo
           1	       1	             22	                   1		Y
           1	       1	             23                           5		Y
           2               2		     14                                        N
           2              2                     21                           4           Y

I want to find the avg of rating and top selected managementinfo(y or n) on formsection columns.

For ex: formsection 1 & 2 has avg rating as 4, and top management is Y.

can any one pls help.


Please post your data in a consumable format:

  1. CREATE TABLE statement
  2. INSERT INTO statement(s) to populate the table from step 1.


Look at this, note I used your example output:

SELECT FormSectionID, AVG(Rating) AS ARat, MAX(ManagementInfo) AS MMI
FROM yourtable 
GROUP BY FormSectionID;

Let us know if you have questions.