-3

我需要显示以超过 20 美元的价格出售物品的人的名字和姓氏,我需要加入标题和作者表但他们没有任何公共键?我该怎么做呢?我只需要显示他们的名字作为输入,这就是我目前所拥有的,我得到的结果是空白的。我只是在学习,所以尽量不要太专业

以下是列名:

authors: pk- au_id
             au_fname
             au_lname
titles: pk- title_id
            title   
            price
        fk- pub_id

这是我到目前为止所拥有的:

select price, au_lname, au_fname
from titles JOIN authors
on authors.au_id=titles.pub_id
4

1 回答 1

1

看起来你也有一张titleauthor桌子。这将有助于您的示例代码中的查询。但是,在这种情况下不需要此表,因为您的问题实际上是在询问销售人员,而不是作者。你真的想要这样的东西:

select distinct e.firstname, e.lastname
from sales s
inner join employee e on e.empl_id = s.empl_id
where s.itemprice >= 20

当然,我不得不在这里对您的列名做出疯狂的猜测。您可以扩展它以包含有关这些项目的标题和作者的信息,如下所示:

select distinct e.firstname as SalePersonFirstName, e.lastname as SalesPersonLastName
    , t.Title, a.Lastname As AuthorLastName, a.firstname as FirstName
    , s.itemprice
from sales s
inner join employee e on e.empl_id = s.empl_id
inner join titles t on t.title_id = sales.title_id
inner join titleauthors ta on ta.title_id = t.title_id
inner join authors a on a.au_id = ta.au_id
where s.itemprice >= 20
于 2015-10-10T22:28:06.523 回答