Group By but include “missing” values
问题 Suppose I have the following. select case when fcompany = 'Acme' then 'Red' when fcompany = 'Acme Rockets' then 'Blue' else 'Green' end Color ,sum(fann_sales) FROM slcdpm group by case when fcompany = 'Acme' then 'Red' when fcompany = 'Acme Rockets' then 'Blue' else 'Green' end Let's say it often returns with only two colors. What's the best way to pull all three colors and include 0 for the missing value? Union All? 回答1: Yes, Union All may be your best bet. SELECT 'red' AS Color, sum(fann