简体   繁体   English

如何在 sql 中使用 group by 语句时检查多个条件

[英]how to check multiple condition while using group by statements in sql

BOOK_ADOPTION (course:int, sem:int, book_isbn:int) BOOK_ADOPTION(课程:int,sem:int,book_isbn:int)

TEXT (book_isbn:int, booktitle: varchar(50), publisher: varchar(50), author: varchar(50)) TEXT(book_isbn:int,书名:varchar(50),出版商:varchar(50),作者:varchar(50))

List the books which are adopted by the course as well as enrolled by the student.列出课程采用的以及学生注册的书籍。

I am trying this:我正在尝试这个:

select course 
from text 
natural join book_adoption 
group by course 
having count(book_isbn)>1 
  and publisher = 'perason';

and getting an error:并得到一个错误:

Unknown column 'publisher' in 'having clause' “有条款”中的未知列“发布者”

but the column publisher is there and even the spelling is correct.但专栏出版商在那里,甚至拼写都是正确的。 Can someone help me out with this one?有人可以帮我解决这个问题吗?

HAVING clause is for using with aggregating functions (like count) but in the case of publisher you have to simply use the WHERE condition. HAVING 子句用于聚合函数(如计数),但在发布者的情况下,您必须简单地使用 WHERE 条件。

select course
from text natural join book_adoption 
where publisher = 'perason'
group by course 
having count(book_isbn)>1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM