Books表具有ID,author_fname,author_lname,标题,release_year。要显示作者的名字和姓氏以及其出版的最小年份,查询将为
SELECT author_fname,
author_lname,
Min(released_year)
FROM books
GROUP BY author_lname,
author_fname;
但是,如果我们还想显示每个作者的第一本书的书名怎么办?不用嵌套查询就可以做到吗?
我尝试过:
SELECT author_fname,
author_lname,
title,
Min(released_year)
FROM books
GROUP BY author_lname,
author_fname;
但是给出了错误的书名。如何解决查询?
答案 0 :(得分:1)
您可以使用correlated
子查询:
select b.*
from books b
where b.released_year = (select min(b1.released_year)
from books b1
where b1.author_lname = b.author_lname and b1.author_fname = b.author_fname
);