Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 364919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:29:05+00:00 2026-05-12T13:29:05+00:00

Given this data set: SummaryID Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9

  • 0

Given this data set:

SummaryID    Q1    Q2    Q3    Q4    Q5    Q6    Q7    Q8    Q9    Q10    Q11    Q12    Q13    Q14    Q15
25           1     2     3     4     5     6     7     6     5     4      3      2      1      2      3
25           1     2     3     4     5     6     7     6     5     4      3      2      1      2      3
25           1     2     3     4     5     6     7     6     5     4      3      2      1      2      3

can the data be PIVOTed or CUBEd or whatever into this:

      0   1   2   3   4   5   6   7
Q1        3      
Q2            3     
Q3                3    
Q4                    3   
Q5                        3  
Q6                            3 
Q7                                3
Q8                            3 
Q9                        3  
Q10                   3   
Q11               3
Q12           3  
Q13       3  
Q14           3 
Q15               3

Essentially, the top table represents how feedback data is stored for a feedback system. Multiple reviewers are asked to rate a single reviewee on a scale from 0 to 7 for 15 questions. My example is a rather unlikely set of responses from 3 reviewers in order to show the pattern in the display table

The second table is how I want to display the data. Each “3” in the table represents the COUNT of responses for the given Q# and Rating combination. E.g., for Q5, 3 reviewees rated this person a “5”.

Clearly, the real data will be much more scattered about.

I’m hoping this is easy.

Thanks,

John Anderson

EDITED: here is my own first attempt:

SELECT * FROM (SELECT SummaryID, COUNT(Q1) AS Q1 FROM SummaryData WHERe SummaryID = 25
GROUP BY SummaryID) o
PIVOT (COUNT(Q1) FOR Q1 IN ([0], [1],[2],[3],[4],[5],[6],[7])) p

SummaryID   0   1   2   3   4   5   6   7
25          0   0   0   1   0   0   0   0

I’m getting a 1 under the 3, which is not right, and I can’t figure out how to extrapolate the code to include all the other Qs.

Thanks again,

John Anderson

EDITED: here is a sample dataset that I modeled in Excel to give results that will more closely resemble reality

SummaryID   Q1   Q2   Q3   Q4   Q5   Q6   Q7   Q8   Q9   Q10   Q11   Q12   Q13   Q14   Q15
25          1    4    5    7    4    2    0    2    1    0     2     2     3     5     0
25          4    1    1    5    6    7    7    4    0    1     3     7     3     1     1
25          5    3    2    1    7    7    4    0    1    6     7     3     2     7     1

Results in:

      0   1   2   3   4   5   6   7
Q1        1           1   1        
Q2        1       1   1            
Q3        1   1           1        
Q4        1               1       1
Q5                    1       1   1
Q6            1                   2
Q7    1               1           1
Q8    1       1       1            
Q9    1   2                        
Q10   1   1                   1    
Q11           1   1               1
Q12           1   1               1
Q13           1   2                
Q14       1               1       1
Q15   1   2                        
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:29:05+00:00Added an answer on May 12, 2026 at 1:29 pm

    You have to UNPIVOT first to get data into a format you need, and then PIVOT

    Working sample:

    SET NOCOUNT ON
    
    DECLARE @Feedback Table 
    (
    SummaryId INT,
    Q01 INT,    Q02 INT,    Q03 INT,    Q04 INT,    Q05 INT,
    Q06 INT,    Q07 INT,    Q08 INT,    Q09 INT,    Q10 INT,
    Q11 INT,    Q12 INT,    Q13 INT,    Q14 INT,    Q15 INT
    )
    
    INSERT INTO @Feedback Values (25, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3)
    INSERT INTO @Feedback Values (25, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3)
    INSERT INTO @Feedback Values (25, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3)
    
    ;WITH ReOrderedData AS
    (
    SELECT SummaryId, QuestionNum, Score, COUNT (*) as NumScores FROM
    (
        SELECT SummaryId, Q01, Q02, Q03, Q04, Q05, Q06, Q07, Q08, Q09, Q10, Q11, Q12, Q13, Q14, Q15
        FROM @Feedback
    ) p
    UNPIVOT (Score For QuestionNum IN (Q01, Q02, Q03, Q04, Q05, Q06, Q07, Q08, Q09, Q10, Q11, Q12, Q13, Q14, Q15)) as UnPvt
    GROUP BY SummaryId, QuestionNum, Score)
    SELECT QuestionNum, 
        IsNull ([0], '') [0], IsNull ([1], '') [1], IsNull ([2], '') [2], IsNull ([3], '') [3], 
        IsNull ([4], '') [4], IsNull ([5], '') [5], IsNull ([6], '') [6], IsNull ([7], '') [7]
    FROM (
    SELECT QuestionNum, Score, NumScores
    FROM ReOrderedData
    ) As SourceTable
    PIVOT
    (
    Max (NumScores) For Score IN ([0], [1], [2], [3], [4], [5], [6], [7])
    ) As Pivotx
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this example data set: ----------------------------- | item | date | val | -----------------------------
Given a data set like this; +-----+---------------------+--------+ | id | date | result |
Given this data set: ID Name City Birthyear 1 Egon Spengler New York 1957
Given this sample data set: Date_Time 10/1/2011 12:05:00 AM 10/6/2011 2:25:00 AM 10/3/2011 5:59:00
given this coffeescript data = Foo: B Foos: [ A, B ] Blah: Id:
Given data like this C1<-c(3,-999.000,4,4,5) C2<-c(3,7,3,4,5) C3<-c(5,4,3,6,-999.000) DF<-data.frame(ID=c(A,B,C,D,E),C1=C1,C2=C2,C3=C3) How do I go about removing
Suppose I am using this data set of movie ratings: http://www.grouplens.org/node/73 It contains ratings
Given a data set of various currency pairs, how do I efficiently compute the
Given this MySQL stored procedure: CREATE PROCEDURE customer.`getCustomers5`( sdf varchar(1000) ) BEGIN set @se
Given the object: // A data set $.DataArea = function () { // Default

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.