日期:2014-05-17 浏览次数:20856 次
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
------解决方案--------------------
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 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