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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:36:13+00:00 2026-06-17T10:36:13+00:00

I am trying to create a query that will generate the following table. I

  • 0

I am trying to create a query that will generate the following table.
I know the column names (that is start and end date of each column. These dates will vary based on the month/year. Also the number of columns will vary since some month may have 6 weeks).

The number of pools may also vary. There can be ‘n’ number of pools. So I have create a query for each pool(row) and for each week(column).
Assume there are 3 pools(3 rows) and 5 weeks (5 columns), I may need to run 3*5=15 queries.
Is there any way to create a single query to fix this?
Can anyone help me in fixing this?
I am stiil working on this..

--------------------------------------------------
row 0 | week1 | week2 | week3  | week4  | week5  |
st-end|jan1 -2|jan 3-9|jan10-17|jan18-24|jan25-31|
--------------------------------------------------
pool a| 100   | 105   | 309    | 345    | 234    |
pool b| 106   | 108   | 399    | 245    | 214    |
pool c| 120   | 145   | 359    | 365    | 274    |
--------------------------------------------------  
  • 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-17T10:36:15+00:00Added an answer on June 17, 2026 at 10:36 am

    Have you tried to do it using CASE expressions? [See “Control Flow Functions”]
    Something along these lines:

    select POOL
          ,sum(case when dt between 20120101 and 20120107 then VAL else 0) as Wk1
          ,sum(case when dt between 20120108 and 20120114 then VAL else 0) as Wk2
        ...  ...
    from MY_TABLE
    group by POOL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a query that will shift the results on each
I'm trying to create a created_at query range that will capture all records created
I'm trying to create a query that will pull the first 10 records of
I'm trying to use LINQ To Objects to create a query that will give
I'm trying to create a parametric query that will be executed in a loop
Ok, I have a SQL query that I'm trying to generate that will combine
I am trying to create a query that will return results for the number
I'm trying to create a query that will return all the jobs published by
I am trying to create a function that will build it's own query with
I am trying to create a query that will display the name, dep no.

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.