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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:16:41+00:00 2026-06-18T03:16:41+00:00

Hello again and thank you in advance for your help. I’ve checked a few

  • 0

Hello again and thank you in advance for your help.

I’ve checked a few prior questions and couldn’t find this exact situation.

I’m trying to transpose/pivot a row to column, but the results are based on a date function in the where clause, making my selects somewhat variable.

SELECT
DATE_FORMAT(packet_details.installDate,'%m-%d-%Y') as Install_Date,
Count(packet_details.installDate)
FROM
packet_details
WHERE
 packet_details.installDate >= CURRENT_DATE - INTERVAL 7 DAY
 AND packet_details.installDate "*lessthan*" CURRENT_DATE + INTERVAL 7 DAY
GROUP BY installDate
*lessthan symbol wont show here on Stack & i don't know how to fix it

Not sure if that makes sense so I included a fiddle: http://sqlfiddle.com/#!2/5b235/3/0
So something like this:

INSTALL_DATE     COUNT
1/24/2013         2
1/25/2013         2
1/26/2013         2
1/27/2013         2
1/28/2013         2
1/29/2013         1
2/3/2013          1
2/4/2013          1
2/5/2013          5
2/6/2013          4

Turned into:

INSTALL_DATE    1/24/2013   1/25/2013   1/26/2013   1/27/2013   1/28/2013....   
COUNT             2             2          2             2         2               1     
  • 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-18T03:16:42+00:00Added an answer on June 18, 2026 at 3:16 am
    SELECT  Install_DATE,
            MAX(CASE WHEN Install_DATE = '01-24-2013' THEN totalCount END) `01-24-2013`,
            MAX(CASE WHEN Install_DATE = '01-25-2013' THEN totalCount END) `01-25-2013`,
            MAX(CASE WHEN Install_DATE = '01-26-2013' THEN totalCount END) `01-26-2013`,
            .......
    FROM
    (
      SELECT DATE_FORMAT(packet_details.installDate,'%m-%d-%Y') as Install_Date,
             Count(packet_details.installDate) totalCount
      FROM   packet_details
      WHERE  packet_details.installDate >= CURRENT_DATE - INTERVAL 7 DAY AND 
             packet_details.installDate   < CURRENT_DATE + INTERVAL 7 DAY
      GROUP  BY installDate
    ) s
    
    • SQLFiddle Demo

    For unknown number of Install_Date, a Dynamic Query is much preferred,

    SET @sql = NULL;
    SELECT
      GROUP_CONCAT(DISTINCT
        CONCAT(
          'MAX(CASE WHEN Install_DATE = ''',
          Install_Date,
          ''' then totalCount end) AS `', Install_Date, '`' )
      ) INTO @sql
    FROM 
    (
      SELECT DATE_FORMAT(packet_details.installDate,'%m-%d-%Y') as Install_Date,
             Count(packet_details.installDate) totalCount
      FROM   packet_details
      WHERE  packet_details.installDate >= CURRENT_DATE - INTERVAL 7 DAY AND 
             packet_details.installDate   < CURRENT_DATE + INTERVAL 7 DAY
      GROUP  BY installDate
    ) s;
    
    SET @sql = CONCAT('SELECT Install_DATE, ', @sql, ' 
                        FROM
                        (
                          SELECT DATE_FORMAT(packet_details.installDate,''%m-%d-%Y'') as Install_Date,
                                 Count(packet_details.installDate) totalCount
                          FROM   packet_details
                          WHERE  packet_details.installDate >= CURRENT_DATE - INTERVAL 7 DAY AND 
                                 packet_details.installDate   < CURRENT_DATE + INTERVAL 7 DAY
                          GROUP  BY installDate
                        ) s');
    
    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello and thank you in advance. This is a follow up question from the
Hello again codes masters, I'm stuck at this piece of codes for dropdown menu.
Hello again everyone, This time I have a problem with Intent & Extras. here's
hello again, WSO2 community. My last question about your architecture for my research is
Hello once again stackoverflow folks, this is really hard and it's been torturing my
hello everyone it is me again! i've got few problems too. i am deveoping
Hello and thanks in advance for any help you can provide. My AIR application
* I'm editing this question because I had a few mistakes, please read again
Hello all and thanks for your time reading this. I need to verify certificates
Hello and thank you in advance! I am setting up a site and it

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.