diff --git a/2208/天天乐学考试答案/MySQL练习(一).md b/2208/天天乐学考试答案/MySQL练习(一).md index 5196944..090fa27 100644 --- a/2208/天天乐学考试答案/MySQL练习(一).md +++ b/2208/天天乐学考试答案/MySQL练习(一).md @@ -243,7 +243,21 @@ WHERE b.note = a.author_name GROUP BY a.author_id HAVING COUNT(*) > 1; +#9 视图 +CREATE VIEW v_book AS +SELECT b.genre, a.author_name, COUNT(*) c +FROM tb_books b, tb_authors a +WHERE b.note = a.author_name +GROUP BY b.genre, a.author_id +HAVING COUNT(*) = ( + SELECT COUNT(*) + FROM tb_books + WHERE b.genre = genre + GROUP BY note + ORDER BY COUNT(*) DESC + LIMIT 1 +); + -#9 ```