select book_id,book_name from 表1 where is_exist=1 and exists (select 1 from 表2 where book_id=表1.book_id) and not exists (select 1 from 表2 where book_id=表1.book_id and user='tom')
select book_id,book_name from 表1 where is_exist=1 and exists (select 1 from 表2 where book_id=表1.book_id) and not exists (select 1 from 表2 where book_id=表1.book_id and user='tom') LIMIT 1 select 表1.book_id,表1.book_name,b.level from 表1,(select book_id,level from 表2 group by book_id,level having count(*)>=3) b where 表1.book_id=b.book_id LIMIT 1
请检索出tom没有读过、而其他人读过的、有货的书
检索出以下几列:书ID,书名,
select book_id,book_name
from 表1
where is_exist=1
and exists (select 1 from 表2 where book_id=表1.book_id)
and not exists (select 1 from 表2 where book_id=表1.book_id and user='tom')
检索2:
检索出至少有三个读者打过分的书,且这些书的打分相同,且书有货
检索出以下几列:书ID,书名,书的级别
select 表1.book_id,表1.book_name,b.level
from 表1,(select book_id,level from 表2 group by book_id,level having count(*)>=3) b
where 表1.book_id=b.book_id
能再问一下么, 怎么限制上面的查询只返回第一条结果啊
拜谢中
from 表1
where is_exist=1
and exists (select 1 from 表2 where book_id=表1.book_id)
and not exists (select 1 from 表2 where book_id=表1.book_id and user='tom')
LIMIT 1 select 表1.book_id,表1.book_name,b.level
from 表1,(select book_id,level from 表2 group by book_id,level having count(*)>=3) b
where 表1.book_id=b.book_id
LIMIT 1