34,591
社区成员
发帖
与我相关
我的任务
分享
select * from 信息表 a where infoId in (select top 2 infoId from 信息表 where sortId=a.sortId and isnull(picture,'')!='' order by infoId desc )--为图片时
union
select * from 信息表 a where infoId in (select top 8 infoId from 信息表 where sortId=a.sortId and isnull(picture,'')='' order by infoId desc )--非图片
搞错:
select * from 表名 a where id in (select top 2 id from 表名 where 栏目=a.栏目 and 图片=1 order by id)--为图片时
union
select * from 表名 a where id in (select top 8 id from 表名 where 栏目=a.栏目 and 图片!=1 order by id)--非图片
select * from 表名 a where exists(select top 2 * from 表名 where 栏目=a.栏目 and 图片=1)--为图片时
union
select * from 表名 a where exists(select top 8 * from 表名 where 栏目=a.栏目 and 图片!=1)--非图片