SQL Sybase - 如何显示在同一行
SQL Sybase - How to display on the same row
抱歉,我是 SQL 的新手,我正在尝试创建一个代码,以提取同一行中的所有值,以及它们各自相同的标识符(fundno 和基金名称)。
我想要的是所有的值都在同一行,而不是分开的。
select
b.fundno,
a.fund_name,
a.fund_type As Type,
a.fund_status_code As Status,
a.category_code as 'CatCode',
convert(char(10),b.prosp_date,101)as 'Prospectus_date',
(case when b.prosp_code = 'GRMFEE' then b.prosp_value end) as GrMgmt,
(case when b.prosp_code = 'GR12B1' then b.prosp_value end) as Gr12b1,
(case when b.prosp_code = 'GROTHR' then b.prosp_value end) as Groth,
(case when b.prosp_code = 'GREXP' then b.prosp_value end) as Grtotal,
(case when b.prosp_code = 'NETMFEE' then b.prosp_value end) as Netmgmt,
(case when b.prosp_code = 'NET12B1' then b.prosp_value end) as Net12b1,
(case when b.prosp_code = 'NETOTHR' then b.prosp_value end) as Netoth,
(case when b.prosp_code = 'EXPLIMIT' then b.prosp_value end) as Nettotal,
(case when b.prosp_code = 'NETWVR' then b.prosp_value end) as Waiver
from
fund a,
prospectus_breakdown b
where a.category_code in(1,13,16,18,19,20,27,31)
and b.fundno = a.fundno
and b.prosp_date=(select max(prosp_date)
from prospectus_breakdown b
where b.fundno=a.fundno)
order by a.fund_name
出现的是这个:
任何人都可以帮我修复代码吗?任何形式的帮助将非常感激。谢谢!!
你想要聚合。 . .和正确的 JOIN
语法:
select f.fundno, f.fund_name, f.fund_type As Type,
f.fund_status_code As Status,
f.category_code as CatCode,
convert(char(10), pb.prosp_date, 101) as Prospectus_date,
max(case when pb.prosp_code = 'GRMFEE' then pb.prosp_value end) as GrMgmt,
max(case when pb.prosp_code = 'GR12B1' then pb.prosp_value end) as Gr12b1,
max(case when pb.prosp_code = 'GROTHR' then pb.prosp_value end) as Groth,
max(case when pb.prosp_code = 'GREXP' then pb.prosp_value end) as Grtotal,
max(case when pb.prosp_code = 'NETMFEE' then pb.prosp_value end) as Netmgmt,
max(case when pb.prosp_code = 'NET12B1' then pb.prosp_value end) as Net12b1,
max(case when pb.prosp_code = 'NETOTHR' then pb.prosp_value end) as Netoth,
max(case when pb.prosp_code = 'EXPLIMIT' then pb.prosp_value end) as Nettotal,
max(case when pb.prosp_code = 'NETWVR' then pb.prosp_value end) as Waiver
from fund f join
prospectus_breakdown pb
on f.fundno = pb.fundo
where f.category_code in (1, 13, 16, 18, 19, 20, 27, 31)
group by f.fundno, f.fund_name, f.fund_type,
f.fund_status_code, f.category_code,
convert(char(10), pb.prosp_date, 101);
备注:
- 从不 在
FROM
子句中使用逗号。
- 始终使用正确、明确的标准
JOIN
语法。
- 使用有意义的 table 别名(table 名称的缩写),而不是任意字母。
- 仅对字符串和日期常量使用单引号,对列别名不使用。
抱歉,我是 SQL 的新手,我正在尝试创建一个代码,以提取同一行中的所有值,以及它们各自相同的标识符(fundno 和基金名称)。
我想要的是所有的值都在同一行,而不是分开的。
select
b.fundno,
a.fund_name,
a.fund_type As Type,
a.fund_status_code As Status,
a.category_code as 'CatCode',
convert(char(10),b.prosp_date,101)as 'Prospectus_date',
(case when b.prosp_code = 'GRMFEE' then b.prosp_value end) as GrMgmt,
(case when b.prosp_code = 'GR12B1' then b.prosp_value end) as Gr12b1,
(case when b.prosp_code = 'GROTHR' then b.prosp_value end) as Groth,
(case when b.prosp_code = 'GREXP' then b.prosp_value end) as Grtotal,
(case when b.prosp_code = 'NETMFEE' then b.prosp_value end) as Netmgmt,
(case when b.prosp_code = 'NET12B1' then b.prosp_value end) as Net12b1,
(case when b.prosp_code = 'NETOTHR' then b.prosp_value end) as Netoth,
(case when b.prosp_code = 'EXPLIMIT' then b.prosp_value end) as Nettotal,
(case when b.prosp_code = 'NETWVR' then b.prosp_value end) as Waiver
from
fund a,
prospectus_breakdown b
where a.category_code in(1,13,16,18,19,20,27,31)
and b.fundno = a.fundno
and b.prosp_date=(select max(prosp_date)
from prospectus_breakdown b
where b.fundno=a.fundno)
order by a.fund_name
出现的是这个:
任何人都可以帮我修复代码吗?任何形式的帮助将非常感激。谢谢!!
你想要聚合。 . .和正确的 JOIN
语法:
select f.fundno, f.fund_name, f.fund_type As Type,
f.fund_status_code As Status,
f.category_code as CatCode,
convert(char(10), pb.prosp_date, 101) as Prospectus_date,
max(case when pb.prosp_code = 'GRMFEE' then pb.prosp_value end) as GrMgmt,
max(case when pb.prosp_code = 'GR12B1' then pb.prosp_value end) as Gr12b1,
max(case when pb.prosp_code = 'GROTHR' then pb.prosp_value end) as Groth,
max(case when pb.prosp_code = 'GREXP' then pb.prosp_value end) as Grtotal,
max(case when pb.prosp_code = 'NETMFEE' then pb.prosp_value end) as Netmgmt,
max(case when pb.prosp_code = 'NET12B1' then pb.prosp_value end) as Net12b1,
max(case when pb.prosp_code = 'NETOTHR' then pb.prosp_value end) as Netoth,
max(case when pb.prosp_code = 'EXPLIMIT' then pb.prosp_value end) as Nettotal,
max(case when pb.prosp_code = 'NETWVR' then pb.prosp_value end) as Waiver
from fund f join
prospectus_breakdown pb
on f.fundno = pb.fundo
where f.category_code in (1, 13, 16, 18, 19, 20, 27, 31)
group by f.fundno, f.fund_name, f.fund_type,
f.fund_status_code, f.category_code,
convert(char(10), pb.prosp_date, 101);
备注:
- 从不 在
FROM
子句中使用逗号。 - 始终使用正确、明确的标准
JOIN
语法。 - 使用有意义的 table 别名(table 名称的缩写),而不是任意字母。
- 仅对字符串和日期常量使用单引号,对列别名不使用。