create view V_Company_Share as
select sum(s.actualprice-s.ownershare)as 'companyShare',year(s.saledate) as 'year'
from sale s, SalesMan sm
where s.SalesmanID=sm.SalesManID
group by year(s.saledate)
select distinct v.year,sm.FirstName+' '+sm.LastName as 'name', v.companyShare
from V_Company_Share v, SalesMan sm,sale s
where v.year=year(s.SaleDate) and s.SalesmanID=sm.SalesManID
感谢分配给帮助者!
答案 0 :(得分:0)
尝试此查询.....
select Max(companyShare),year,SalesmanID (
select sum(s.actualprice-s.ownershare)as [companyShare]
,year(s.saledate) as [year]
,s.SalesmanID as [SalesmanID]
from sale s, SalesMan sm
where s.SalesmanID=sm.SalesManID
group by year(s.saledate)
)
group by year
答案 1 :(得分:0)
尝试此查询...
select Max(companyShare),year,SalesmanID from
(
select sum(s.actualprice-s.ownershare)as [companyShare]
,year(s.saledate) as [year]
,s.SalesmanID as [SalesmanID]
from sale s, SalesMan sm
where s.SalesmanID=sm.SalesManID
group by year(s.saledate)
)A
group by year
如果逻辑错误,请尝试使用o / p
发布演示数据