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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:17:46+00:00 2026-06-08T12:17:46+00:00

http://sqlfiddle.com/#!3/e4891/1 for the above resulting query(which pivots data) I want to run my one

  • 0

http://sqlfiddle.com/#!3/e4891/1

for the above resulting query(which pivots data) I want to run my one more select condition.

For example

select (C1 & C2) from ‘the above pivoted query results’

IS it possible to do it? CTE will help here?
SQL Server 2008 and above.

  • 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-06-08T12:17:47+00:00Added an answer on June 8, 2026 at 12:17 pm

    Try this:

    WITH Data AS 
    (
      select *
     from 
     (
        select MemId, Condition_id, condition_result
        from t
     ) x
     pivot
     (
        sum(condition_result)
        for condition_id in ([C1], [C2], [C3], [C4])
     ) p
    )
    SELECT C1, C2
      FROM Data
    

    SQLFiddle: http://sqlfiddle.com/#!3/e4891/3

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see http://www.sqlfiddle.com/#!3/fb107/3 for an example schema and query I want to run. I
http://sqlfiddle.com/#!2/6a6b1 The scheme is given above.. all I want to do is get the
Check this example before reading the question - http://www.sqlfiddle.com/#!2/fcf3e/8 The following data comes from
Quick update -- SQLFiddle link: http://sqlfiddle.com/#!2/d038f/2 I think it's a relatively straight forward one...
http://localhost:8080/search/terms?terms.prefix=ab&terms.fl=text&terms.sort=count I have the above terms query which works as I expect. Returns all
I have some data in a format described in this sqlfilddle: http://sqlfiddle.com/#!4/b9cdf/2 Basically, a
I have the following minimal schema in Oracle: http://sqlfiddle.com/#!4/c1ed0/14 The queries I have run
I have such a schema and queries: http://sqlfiddle.com/#!2/7b032/3 Seperately I have these queries: SELECT
I have 3 tables and I want to join it. Check this fiddle: http://sqlfiddle.com/#!2/20410/2
Here's the basic guts of my schema and problem: http://sqlfiddle.com/#!1/72ec9/4/2 Note that the periods

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.