我试过IN,多个喜欢的句子等。
问题: 列出由Jove,Penguin,Plume和Scholastic出版的书籍。在出版商中按标题组织。
desc表
SQL> desc book
Name
------------------
BOOK_CODE
TITLE
PUBLISHER_CODE
TYPE
PRICE
PAPERBACK
sql我试过
SQL> select * from BOOK where Publisher_Code IN(JP,PE,PL,SS)
2 group by Publisher_code, title;
SQL> select * from BOOK
2 where PUBLISHER_CODE IN('%JP%', '%PE%','%PL%', '%SC%')
3 group by title, Publisher_code;
SQL> select * from book
2 where Publisher_code like '%JP%'
3 OR where Publisher_code like '%PE%'
4 OR where Publisher_code like '%PL%'
5 OR where Publisher_code like '%SC%'
6 group by Publisher_code
7 order by title;
答案 0 :(得分:4)
目前还不清楚您使用group by
的原因。你想要order by
。您的示例查询具有非常基本的SQL错误,例如在查询中重复where
关键字。这是一个似乎可以做你想要的版本:
select b.*
from book b
where b.Publisher_code like '%JP%' or
b.Publisher_code like '%PE%' or
b.Publisher_code like '%PL%' or
b.Publisher_code like '%SC%'
order by b.Publisher_code, b.Title;
作为注释:大概是发布商代码是常量,您不需要将like
与通配符一起使用。