27,579
社区成员
发帖
与我相关
我的任务
分享
SELECT TOP 2
* ,
number = ( SELECT COUNT(*)
FROM et_ztea_images AS i
WHERE i.tea_albumid = a.id
) ,
imagepath = ( SELECT TOP 1
imagepath
FROM et_ztea_images AS z
WHERE z.tea_albumid = a.id
) ,
picid = ( SELECT TOP 1
id
FROM et_ztea_images AS z
WHERE z.tea_albumid = a.id
)
FROM et_ztea_Album AS a
WHERE teaid = 326
AND EXISTS(SELECT 1 FROM et_ztea_images b WHERE a.id = b.tea_albumid) --加了这句
ORDER BY AlbumTime DESC
SELECT TOP 2
* ,
number = ( SELECT COUNT(*) FROM et_ztea_images AS i WHERE i.tea_albumid = a.id) ,
imagepath = ( SELECT TOP 1 imagepath FROM et_ztea_images AS z WHERE z.tea_albumid = a.id) ,
picid = ( SELECT TOP 1 id FROM et_ztea_images AS z WHERE z.tea_albumid = a.id)
FROM et_ztea_Album AS a
WHERE teaid = 326
AND (SELECT COUNT(*) FROM et_ztea_images AS i WHERE i.tea_albumid = a.id) <> 0
ORDER BY AlbumTime DESC
select * from
(
select top 2 *,number=
(select COUNT(*) from et_ztea_images as i where i.tea_albumid=a.id),
imagepath=(select top 1 imagepath from et_ztea_images as z where
z.tea_albumid=a.id),picid=(select top 1 id from et_ztea_images as z
where z.tea_albumid=a.id) from et_ztea_Album as a where teaid=326
order by AlbumTime desc
) t
where number<>0
;with t as
(
select top 2 *,number=
(select COUNT(*) from et_ztea_images as i where i.tea_albumid=a.id),
imagepath=(select top 1 imagepath from et_ztea_images as z where
z.tea_albumid=a.id),picid=(select top 1 id from et_ztea_images as z
where z.tea_albumid=a.id) from et_ztea_Album as a where teaid=326
order by AlbumTime desc
)
select * from t where number<>0