How do I Put Several Select Statements into Different Columns
- by Russ Bradberry
I basically have 7 select statement 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 '1' FROM event_log_facts WHERE date_dim_id=20100101
SELECT COUNT(user_id) AS '2' FROM event_log_facts WHERE date_dim_id=20100102
SELECT COUNT(user_id) AS '3' FROM event_log_facts WHERE date_dim_id=20100103
SELECT COUNT(user_id) AS '4' FROM event_log_facts WHERE date_dim_id=20100104
SELECT COUNT(user_id) AS '5' FROM event_log_facts WHERE date_dim_id=20100105
SELECT COUNT(user_id) AS '6' FROM event_log_facts WHERE date_dim_id=20100106
SELECT COUNT(user_id) AS '7' FROM event_log_facts WHERE date_dim_id=20100107