涉及到两个表的查询 count
表album:aid,aname,smallpic (aid为主键)
表photo:aid,pid,photopath……(aid为外键,pid为主键)
现在需要取到最新的三个album,且要得到每个album有多少张photo:
select top 3 album.aid, album.aname,album.smallpic, A.amount from album join ( select aid,count(*) as amount from photo group by aid)A
on album.aid=A.aid
表album:aid,aname,smallpic (aid为主键)
表photo:aid,pid,photopath……(aid为外键,pid为主键)
现在需要取到最新的三个album,且要得到每个album有多少张photo:
select top 3 album.aid, album.aname,album.smallpic, A.amount from album join ( select aid,count(*) as amount from photo group by aid)A
on album.aid=A.aid