论坛上看到有人说having子句不能单独使用,后面还有很多人赞同,我表示不能忍了..例子,举个最简单的select 1 from dual having count(1) = 1;
再说一个用途--书
create table book as
select 1 id,'小说A' name from dual union all
select 2 , '小说B' from dual union all
select 3 , '小说C' from dual;--用户读那本书
create table book_reader as
select 111 id, 1 bookid from dual union all
select 112 , 1 from dual union all
select 113 , 2 from dual ;--只有一个用户读的书
select *
from book a
where exists (select 1
from book_reader b
where a.id = b.bookid
having count(1) = 1);
再说一个用途--书
create table book as
select 1 id,'小说A' name from dual union all
select 2 , '小说B' from dual union all
select 3 , '小说C' from dual;--用户读那本书
create table book_reader as
select 111 id, 1 bookid from dual union all
select 112 , 1 from dual union all
select 113 , 2 from dual ;--只有一个用户读的书
select *
from book a
where exists (select 1
from book_reader b
where a.id = b.bookid
having count(1) = 1);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货