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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:30:57+00:00 2026-05-15T22:30:57+00:00

A table lists multiple events where each event has four attributes (columns), call them

  • 0

A table lists multiple events where each event has four attributes (columns), call them A, B, C, P

It would be simpleto pivot to get a table with columns for A, B, C, P=1, P=2, P=3, etc.

However, I need the columns to be A, B, C, P<1, P<2, P<3, etc.

In other words, if a row of the “simple” way were X, Y, Z, 7, 3, 5, 2 then what I actually need is X, Y, Z, 7, 10, 15, 17 because any P less than N is also less than N+1.

I know I can compute the values (X, Y, Z, 7, 10, 15, 17), load them into a temporary table, and pivot that, but maybe there’s something simple that my SQL talents don’t recognize immediately?

If it matters, the result will end up in SSRS.

  • 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-15T22:30:57+00:00Added an answer on May 15, 2026 at 10:30 pm

    If I understand you correctly, then this should work.

    SELECT
        A,
        B,
        C,
        SUM(CASE WHEN P < 1 THEN 1 ELSE 0 END) AS P1,
        SUM(CASE WHEN P < 2 THEN 1 ELSE 0 END) AS P2,
        SUM(CASE WHEN P < 3 THEN 1 ELSE 0 END) AS P3,
        SUM(CASE WHEN P < 4 THEN 1 ELSE 0 END) AS P4
    FROM
        Events
    GROUP BY
        A,
        B,
        C
    

    This is not dynamic. For example, if you have a row in there with P=4 then it will not add a row for P<5. It’s also using strictly < and not <=.

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

Sidebar

Related Questions

I have a table with many rows and each row has select lists. Something
I have a table with multiple rows in each row is a select list
I have the following table that lists all awarded cups: Name: Cups Columns: Month,
I have a database containing two tables: event and session (one event has multiple
I have a generated table that contains multiple rows with each row containing a
I have a table with four columns. Three of which are settings for the
I have a table that contains multiple dropdown menus for a list of profile
I'm trying to join multiple tables together for building a report. The report lists
I've got a large table that lists out approximately 50 users and some simple
I have a table named tbl_Subjects_Taken which lists all the subjects taken by the

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.