我有两张桌子
那么,我怎样才能找到指定日期的最大“已发行图书名称”。
答案 0 :(得分:3)
select top 1 book.bookid, book.bookname from
(
select bookid, sum(qty) as s
from issue
where issuedate = @issuedate
group by bookid
) grp
inner join book
on book.bookid = grp.bookid
order by s
如果“最大”,则表示“在给定日期发出的数量最大的图书的名称”。
答案 1 :(得分:0)
这样的事情:
select BookName from Book
where BookId = (select BookId from Issue where IssueDate = @yourdate
AND Qty = (select MAX(Qty) from Issue))