这可能是一个简单的语法错误,但我一直在看它一个小时而我找不到它,也许另一组眼睛可以帮我指向正确的方向?
select
lname +', '+ Fname as "Author Name"
from
Author a
join
BOOKAUTHOR ba on a.AuthorID = ba.authorid
where
ba.isbn = (select ba.isbn
from
(select
ROW_NUMBER() over (order by sum(quantity) desc) as "Placement",
b.isbn,
sum(QUANTITY) as "Total"
from
ORDERITEMS oi
join
Books b on b.ISBN = oi.isbn
group by
b.ISBN)
where Placement = 1) --the "WHERE" is giving me an error.
答案 0 :(得分:4)
当FROM子句将派生表指定为表源时,必须为子查询指定别名:
select lname +', '+ Fname as "Author Name"
from Author a
join BOOKAUTHOR ba on
a.AuthorID = ba.authorid
where ba.isbn =
(select q.isbn -- <== notice the "q"
from
(select ROW_NUMBER()
over (order by sum(quantity) desc) as "Placement",
b.isbn,
sum(QUANTITY) as "Total"
from ORDERITEMS oi
join Books b
on b.ISBN = oi.isbn
group by b.ISBN) q -- <== notice the "q"
where Placement = 1)
[ FROM { <table_source> } [ ,...n ] ]
<table_source> ::=
{
...
| derived_table [ AS ] table_alias [ ( column_alias [ ,...n ] ) ]
...
}