
数据库有省,市,县三张表,怎么查出每个省有几个县
三张表:a(省表字段:sid,sname),b(市表字段:shid,shname,sid(FK)),c(县表字段:xid,xname,shid(FK)),问题是:怎么查出...
三张表:a(省表字段:sid,sname),
b(市表字段:shid,shname,sid(FK)),
c(县表字段:xid,xname,shid(FK)),
问题是:怎么查出每个省有多少个县 展开
b(市表字段:shid,shname,sid(FK)),
c(县表字段:xid,xname,shid(FK)),
问题是:怎么查出每个省有多少个县 展开
展开全部
select a.sname,count(*) from a,b,c
where a.sid=b.sid and b.shid=c.shid
group by a.sname
where a.sid=b.sid and b.shid=c.shid
group by a.sname
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询