SQL 怎么对已有查询结果建立 视图 再进行查询
select*,rownum=row_number()over(orderby[%Value]desc)from(select*,(A.TotalCA/B.SUMValu...
select *,rownum=row_number() over (order by [%Value] desc) from
(
select *,
(A.TotalCA/B.SUMValue) AS [%Value],
(A.TotalKG/B.SUMVolume) as [%Volume]
FROM(
select [Supply Chain],[Region],[Mat type name],[Plant],[Mat name],[MONTH],
SUM([Vol INV total KG]) as TotalKG,
SUM([Val INV total CA]) AS TotalCA
from [INVENTORY$]
GROUP BY [Supply Chain],[Region],[Mat type name],[Plant],[Mat name],[Month]
)A,
(select sum([Val INV total CA]) AS SUMValue,
sum([Vol INV total KG]) as SUMVolume
FROM [INVENTORY$])B
) as c
这段代码已经调试成功,简写就是
select (
【原始代码】
) as d
我想在这个基础上对%Value累计求和。于是我对d建立了一个视图, 再累计查询,但是不对,请问怎么改呢,万分感谢各位了。
create view d as
select *, (select sum([%Value]) from d as e where d.rownum<= f.rownum) as accumulaSumVal
from d as f
select (
【原始代码】
) as d 展开
(
select *,
(A.TotalCA/B.SUMValue) AS [%Value],
(A.TotalKG/B.SUMVolume) as [%Volume]
FROM(
select [Supply Chain],[Region],[Mat type name],[Plant],[Mat name],[MONTH],
SUM([Vol INV total KG]) as TotalKG,
SUM([Val INV total CA]) AS TotalCA
from [INVENTORY$]
GROUP BY [Supply Chain],[Region],[Mat type name],[Plant],[Mat name],[Month]
)A,
(select sum([Val INV total CA]) AS SUMValue,
sum([Vol INV total KG]) as SUMVolume
FROM [INVENTORY$])B
) as c
这段代码已经调试成功,简写就是
select (
【原始代码】
) as d
我想在这个基础上对%Value累计求和。于是我对d建立了一个视图, 再累计查询,但是不对,请问怎么改呢,万分感谢各位了。
create view d as
select *, (select sum([%Value]) from d as e where d.rownum<= f.rownum) as accumulaSumVal
from d as f
select (
【原始代码】
) as d 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询