I have the following table:
| post_state | total_posts | | opened | 1000 | | completed | 2000 |
I’m using this query to get the above result:
SELECT post_state, SUM(total_threads) as total_posts, FROM data.table WHERE post_state IN ('opened', 'completed') GROUP BY post_state
However, I would like to combine both rows in a single one, something like this:
| post_state | total_posts | | all_posts | 3000 |
How am I able to output this in Google SQL? I’m new to SQL world, happy if you could help me out 🙂
Thanks in advance for the assistance.
Advertisement
Answer
Just remove GROUP BY post_state
:
SELECT 'all_posts' as post_state, SUM(total_threads) as total_posts, FROM data.table WHERE post_state IN ('opened', 'completed')