SQL,显示列表发布者ID,发布者名称,标题和价格最高的书籍的价格

时间:2016-11-16 07:39:20

标签: sql sql-server

列出出版商ID,出版商名称,最高价格书籍的标题和价格

表1

Books
  .ISBN
  .Title
  .PubDate
  .PubID
  .Cost
  .Retail
  .Category

表2

Publisher
  .PubId
  .Name
  .Contact
  .Phone

3 个答案:

答案 0 :(得分:2)

尝试下面的解决方案,那会有效!

SELECT tbl1.pubID as 'Publisher ID', 
             tbl2.Publisher as 'Publisher Name',
             tbl1.Title, 
             tbl1.Cost
FROM tables1 tbl1 
INNER JOIN tables2 tbl2 ON tbl1.pubID = tbl2.pubID
WHERE tbl1.Cost IN (SELECT MAX(tt.Cost) FROM tables1 tt)

答案 1 :(得分:1)

SELECT top 1 tbl1.pubID as 'Publisher ID', 
             tbl2.Publisher as 'Publisher Name',
             tbl1.Title, 
             tbl1.Cost
FROM tables1 tbl1 
INNER JOIN tables2 tbl2 ON (tbl1.pubID = tbl2.pubID)
ORDER BY tbl1.cost DESC

答案 2 :(得分:0)

SELECT tbl1.pubID as 'Publisher ID', tbl2.Publisher as 'Publisher Name', tbl1.Title, tbl1.Cost
FROM tables1 tbl1 INNER JOIN tables2 tbl2 ON (tbl1.pubID = tbl2.pubID)
ORDER BY tbl1.cost DESC;