我在 oracle 10g 中有下表(company_details)。
STATE COMPANY_NAME AVG_SAL
KN GOO $5500
IN SCOPE $6000
AR FB $8250
CL PAL $4500
CL GOO $6000
AR GOO $7000
IN FB $3999
我想形成如下所示的输出并将其显示在简单的 GWT 数据网格中。
STATE count(goo) AVG_SAL count(SCOPE) AVG_SAL count(FB) AVG_SAL count(PAL) AVG_SAL
KN 1 5500 -- -- -- -- -- --
IN -- -- 1 6000 1 3999 -- --
AR 1 7000 -- -- 1 8250 -- --
CL 1 6000 -- -- -- -- 1 4500
我尝试编写以下查询,但没有成功。请帮助
select
state,
count(*)as "GOO_Records", to_char(SUM(average_sal),'$999,999') as "GOO_AVGSAL"
from company_details
where company_status = 'OPEN' and COMPANY_NAME = 'GOO' group by state order by state
union
select
state,
count(*)as "FB_Records", to_char(SUM(average_sal),'$999,999') as "FB_AVGSAL"
from company_details
where company_status = 'OPEN' and COMPANY_NAME = 'FB' group by state order by state
任何帮助表示赞赏。提前致谢!!!!