有关数据库管理系统的查询

时间:2016-08-25 07:34:22

标签: mysql sql database

我想写这些查询

  • 显示从未借过诗歌的学生的名字。
  • 显示借出超过5本书的学生姓名。
  • 显示所有已出版图书的学生姓名,图书标题,发行日期和作者姓名。

到目前为止我写的查询不适用于第一个任务

SELECT 
    name       
FROM 
    students
INNER JOIN issued ON students.rollno = issued.rollno
GROUP BY 
    issued.rollno
HAVING 
    COUNT( issued.rollno )> 2

1 个答案:

答案 0 :(得分:0)

尝试这些查询

select s.name from students s
left join issued i on (s.rollno = i.rollno)
left join bookcopy bc on (i.copyid = bc.copyid)
left join books b on (bc.bookid = b.bookid)
left join category c on (b.catid = c.catid and c.catname = 'Poetry')
where c.catid is null

select s.name, count(*) as from students s
left join issued i on (s.rollno = i.rollno)
group by s.name
having count(*) > 5

select s.name, b.title, a.authorname, i.issuedate from students s
left join issued i on (s.rollno = i.rollno)
left join bookcopy bc on (i.copyid = bc.copyid)
left join books b on (bc.bookid = b.bookid)
left join author a on (b.authorid = a.authorid);