我有下表:
State Soccer players Tennis players
CT 0 0
IL 5 10
IN 3 8
MI 12 14
OH 8 9
AR 2 2
KS 14 16
AL 8 7
CA 1 13
NV 2 3
我想形成一个如下所示的输出表
Region Total_players
East 0
MidWest 60
SouthWest 34
West 29
SouthEast 0
我也试图在没有任何球员的东部地区获得结果。但是,在我的结果集中,我没有得到“东”。
我尝试了以下不产生“东部”区域的查询。
select CASE
WHEN STATE IN ('AL','FL','GA','KY','LA','MS','NC','SC','TN') THEN 'SE'
WHEN STATE IN ('IL','IN','MI','OH','WI') THEN 'MW'
WHEN STATE IN ('AR','KS','MO','OK','TX') THEN 'SW'
WHEN STATE IN ('CT') THEN 'E'
WHEN STATE IN ('CA','NV') THEN 'W'
ELSE 'Error'
END AS Region,
COUNT(*) as Total,
from players WHERE TRUNC(t.date) >= to_char(to_date(?,'DY MON DD HH24:MI:SS YYYY'),'DD-MON-YYYY')
and TRUNC(t.date) <= to_char(to_date(?,'DY MON DD HH24:MI:SS YYYY'),'DD-MON-YYYY')
GROUP BY ROLLUP(Region) ORDER BY Region