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 6668015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:59:39+00:00 2026-05-26T02:59:39+00:00

Can you pivot two columns in a pivot query. Suppose I have the following

  • 0

Can you pivot two columns in a pivot query.

Suppose I have the following data…

CREATE TABLE JudgeScores 
    (PerformanceID int, 
    JudgeID int, 
    Criteria varchar(10), 
    StrengthScore decimal(9,4), 
    StyleScore decimal(9,4))

--first team performance
--judge1
INSERT INTO JudgeScores (1, 1, "Stunts",        4.2, 1.1)
INSERT INTO JudgeScores (1, 1, "Jumps",         3.9, 0.8)
INSERT INTO JudgeScores (1, 1, "Tumbling",      4.5, 1.0)
INSERT INTO JudgeScores (1, 1, "Choreography",  4.2, 1.5)
--judge2
INSERT INTO JudgeScores (1, 2, "Stunts",        4.1, 1.1)
INSERT INTO JudgeScores (1, 2, "Jumps",         4.0, 0.9)
INSERT INTO JudgeScores (1, 2, "Tumbling",      4.4, 1.1)
INSERT INTO JudgeScores (1, 2, "Choreography",  4.2, 1.6)

--judge3
INSERT INTO JudgeScores (1, 3, "Stunts",        3.8, 1.2)
INSERT INTO JudgeScores (1, 3, "Jumps",         4.2, 0.7)
INSERT INTO JudgeScores (1, 3, "Tumbling",      4.3, 1.2)
INSERT INTO JudgeScores (1, 3, "Choreography",  4.1, 1.3)


--second team performance
--judge1
INSERT INTO JudgeScores (2, 1, "Stunts",        4.3, 1.3)
INSERT INTO JudgeScores (2, 1, "Jumps",         4.0, 0.9)
INSERT INTO JudgeScores (2, 1, "Tumbling",      4.6, 1.1)
INSERT INTO JudgeScores (2, 1, "Choreography",  4.0, 1.0)
--judge2
INSERT INTO JudgeScores (2, 2, "Stunts",        4.1, 1.1)
INSERT INTO JudgeScores (2, 2, "Jumps",         4.0, 0.9)
INSERT INTO JudgeScores (2, 2, "Tumbling",      4.5, 1.2)
INSERT INTO JudgeScores (2, 2, "Choreography",  4.2, 1.6)

--judge3
INSERT INTO JudgeScores (2, 3, "Stunts",        4.1, 1.1)
INSERT INTO JudgeScores (2, 3, "Jumps",         4.5, 0.9)
INSERT INTO JudgeScores (2, 3, "Tumbling",      4.4, 1.2)
INSERT INTO JudgeScores (2, 3, "Choreography",  4.2, 1.6)

I want to select the data so that it will pivot this data as follows

PerformanceID, JudgeID, StuntsStrength, StuntsStyle, JumpsStrength, JumpsStyle, TumbleStrength, TumbleStyle, ChorStrength, ChorStyle
1     1     4.2,    1.1,    3.9,    0.8,   4.5,   1.0,    4.2,     1.5
1     2     4.1,    1.1,    4.0,    0.9,   4.4,   1.1,    4.2,     1.6
...
2     1     4.3,    1.3,    4.0,    0.9,   4.6,   1.1,    4.0,    1.0
2     2     4.1,    1.1,    4.0,    0.9,   4.5,   1.2,    4.2,    1.6
2     3     ...

Can this be done with a pivot query. If not what is the best way to do it?

  • 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-26T02:59:40+00:00Added an answer on May 26, 2026 at 2:59 am

    IMO this is more readable than the pivot equivalent.

    Keep it simple and maintainable:

     select PerformanceId,
            JudgeId,
            [StuntsStrength] = avg(case when Criteria = 'Stunts' then StrengthScore else null end),
            [StuntsStyle] = avg(case when Criteria = 'Stunts' then StyleScore else null end),
            [JumpsStrength] = avg(case when Criteria = 'Jumps' then StrengthScore else null end),
            [JumpsStyle] = avg(case when Criteria = 'Jumps' then StyleScore else null end),
            [TumbleStrength] = avg(case when Criteria = 'Tumbling' then StrengthScore else null end),
            [TumbleStyle] = avg(case when Criteria = 'Tumbling' then StyleScore else null end),
            [ChorStrength] = avg(case when Criteria = 'Choreography' then StrengthScore else null end),
            [ChorStyle] = avg(case when Criteria = 'Choreography' then StyleScore else null end)
    from    dbo.JudgeScores
    group
    by      PerformanceId, JudgeId;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you had this table: CREATE TABLE Records ( RecordId int IDENTITY(1,1) NOT NULL,
I am using excel 2010. I am trying to create pivot table between two
Using the MySQL query below, I have created a pivot table which is pretty
Can you use calculated fields in Excel 2007 pivot tables when the data source
Right bit of a simple question can I input nText into a pivot table?
I have a problem with creating a pivot table in PostgreSQL using the crosstab()
I need to create a random array of int and have it sorted by
Suppose I have this database table (some sample code below) that stores the relationship
I have a table that contains, among other things, about 30 columns of boolean
I have two tables. In one table we enter all types of Models, each

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.