Senior
SQL task: write a query to select the first 100 books starting with 'History', published before a certain year, with an author no older than 70 years.
sobes.tech AI
Answer from AI
sql SELECT * FROM books b JOIN authors a ON b.author_id = a.id WHERE b.title LIKE 'История%' AND b.published_year < @year AND a.age <= 70 ORDER BY b.published_year DESC LIMIT 100;
In this query:
books— table with books, containing fieldstitle(name),published_year(year of publication),author_id(author's identifier).authors— table with authors, containing the fieldage(age).@year— parameter specifying the upper limit of the publication year.
The query selects the first 100 books with titles starting with "История", published before the specified year, and whose authors are no older than 70 years.