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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:53:16+00:00 2026-05-13T23:53:16+00:00

I basically have 7 select statements that I need to have the results output

  • 0

I basically have 7 select statements that I need to have the results output into separate columns. Normally I would use a crosstab for this but I need a fast efficient way to go about this as there are over 7 billion rows in the table. I am using the vertica database system. Below is an example of my statements:

SELECT COUNT(user_id) AS '20100101' FROM event_log_facts WHERE date_dim_id=20100101
SELECT COUNT(user_id) AS '20100102' FROM event_log_facts WHERE date_dim_id=20100102
SELECT COUNT(user_id) AS '20100103' FROM event_log_facts WHERE date_dim_id=20100103
SELECT COUNT(user_id) AS '20100104' FROM event_log_facts WHERE date_dim_id=20100104
SELECT COUNT(user_id) AS '20100105' FROM event_log_facts WHERE date_dim_id=20100105
SELECT COUNT(user_id) AS '20100106' FROM event_log_facts WHERE date_dim_id=20100106
SELECT COUNT(user_id) AS '20100107' FROM event_log_facts WHERE date_dim_id=20100107

should return something like:

20100101 | 20100102 | 20100103 | 20100104 | 20100105 | 20100106 | 20100107
1234     | 1234     | 36564    | 45465    | 356754   | 3455     | 4556675
  • 1 1 Answer
  • 4 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-13T23:53:16+00:00Added an answer on May 13, 2026 at 11:53 pm

    You could use a series of queries unioned together. Kind of ugly, but it should work

    SELECT  
      COUNT(user_id) AS '20100101'  
     ,NULL AS '20100102'  
     ,NULL AS '20100103'  
     ,NULL AS '20100104'  
     ,NULL AS '20100105'  
    FROM  
      event_log_facts  
    WHERE  
      date_dim_id=20100101  
    UNION  
    SELECT  
      NULL AS '20100101'  
     ,COUNT(user_id) AS '20100102'  
     ,NULL AS '20100103'  
     ,NULL AS '20100104'  
     ,NULL AS '20100105'  
    FROM   
      event_log_facts  
    WHERE  
      date_dim_id=20100102  
    UNION  
    SELECT  
      NULL AS '20100101'  
     ,NULL AS '20100102'  
     ,COUNT(user_id) AS '20100103'  
     ,NULL AS '20100104'  
     ,NULL AS '20100105'  
    FROM  
      event_log_facts  
    WHERE  
      date_dim_id=20100103  
    

    ETC…

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

Sidebar

Related Questions

Basically I have a asp.net that I need to display an XML document (straight
If I were to select a row from a table I basically have two
I have a stored procedure which basically does something like select top 1 expiryDate,
I basically have a web-browser control that is going through and automatically completing some
I have a large auditing stored procedure that prints values and runs some SELECT
I have a SQL Select statement where I need to return certain values depending
I have several laptops in the field that need to daily get information from
I have a set of PDO statements that do not seem to be working.
I have a select statement returning 5 columns: select col1,col2,col3,col4,col5 from table1; col1 col2
Ok, I have two tables that I am joining and doing a select on

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.