表一 aid title
1 book
2 frout
3 pen
4 mouse
表二 bsid id content
1 1 thisisbook
2 1 fsafssdfsdf
3 2 hfdgdgfdg
4 2 wdsfsdfsf表一和表二通过id关联。表一的id 和表二的sid都是主键,自增。要求选出 表一的 id,title,记录数这个记录数的意思是表一的id在表二里有多少条记录(也就是属于这个类别的记录有多少条的意思),并且这个记录数要大于10小于50。 不知道sql语句怎么写?
1 book
2 frout
3 pen
4 mouse
表二 bsid id content
1 1 thisisbook
2 1 fsafssdfsdf
3 2 hfdgdgfdg
4 2 wdsfsdfsf表一和表二通过id关联。表一的id 和表二的sid都是主键,自增。要求选出 表一的 id,title,记录数这个记录数的意思是表一的id在表二里有多少条记录(也就是属于这个类别的记录有多少条的意思),并且这个记录数要大于10小于50。 不知道sql语句怎么写?
from A,B
where A.id=B.id
group by A.id,A.title
having count(*)>10 and count(*)<50
from a
inner Join
(select id,count(1) 记录数 from b group by id having count(1) between 10 and 50)bb
On a.id=bb.id