34,838
社区成员




select a.* ,b.Name
from Album a left join Photo B on a.ID= AlbumID and a.PicCount >0
and not exists (select 1 from Photo where AlbumID=b.AlbumID and id<b.Id)
select a.* ,b.Name
from Album a left join Photo B on a.ID= AlbumID and a.PicCount >0
select a.id,a.name,case when a.piccount>0 then c.name else null end
from album a,(select * from photo b where not exists(select 1 from photo where albumid=b.albumid and id<a.id))c where a.id=c.albumid
select a.* ,b.Name
from Album a left join (select AlbumID ,name from Photo t where not exists (select 1 from Photo where t.AlbumID=AlbumID and a.ID>ID )) b on a.ID= AlbumID
select a.* ,
case when piccount > 0 then (select top 1 name from photo where albumid = a.id order by id)
else null
end
from album a