菜鸟求助,视图生成中遇到的问题
想生成一个汇总视图,其中一列为源数据表相同编号行的和
select
sjbh,sjmc,kssc,mtdw,
sum(fz) as zf
from sjtmb where autoid in (select max(autoid) from sjtmb group by sjbh)
这样写是报错的,不知道有没有高手能解决一下,不胜感激
fz(分值)是源数据表里的,现在想在视图中显示zf(总分) sql 视图 聚合
[解决办法]
select a.sjbh,a.sjmc,a.kssc,a.mtdw,sum(a.fz) as zf
from sjtmb a
inner join (select sjbh,max(autoid) as autoid from sjtmb group by sjbh) b
on a.autoid=b.autoid and a.sjbh=b.sjbh
group by a.sjbh,a.sjmc,a.kssc,a.mtdw
select a.sjbh,a.sjmc,a.kssc,a.mtdw,
(select sum(b.fz) from sjtmb b
where b.autoid=a.autoid --> 相同编号行的条件
) 'zf'
from sjtmb a