select branch.Librarian, Branch.[Address], SUM(NumberOfCopies) as Number
from Branch,Holding
where Branch.Id=Holding.BranchId
group by Branch.Librarian,Branch.Address
having Number>10如上,having Number>10提示错。
如果我想为SUM(NumberOfCopies)设置一个简称,并在having中使用,应该怎么做呢?
from Branch,Holding
where Branch.Id=Holding.BranchId
group by Branch.Librarian,Branch.Address
having Number>10如上,having Number>10提示错。
如果我想为SUM(NumberOfCopies)设置一个简称,并在having中使用,应该怎么做呢?
from Branch,Holding
where Branch.Id=Holding.BranchId
group by Branch.Librarian,Branch.Address
having SUM(NumberOfCopies)>10
from(
select branch.Librarian, Branch.[Address], SUM(NumberOfCopies) as Number
from Branch,Holding
where Branch.Id=Holding.BranchId
group by Branch.Librarian,Branch.Address
) as t
where Number>10
cte tbl as (
SELECT branch.librarian,
branch.[Address],
SUM(numberofcopies) AS NUMBER
FROM branch,
holding
WHERE branch.id = holding.branchid
GROUP BY branch.librarian,
branch.address
)
SELECT *
FROM tbl
WHERE NUMBER > 10
楼主注意,别名请别用Number这样的敏感字眼,如果实在要用可以用[Number]括住