日期:2014-05-17 浏览次数:20880 次
select * from
(select
ROW_NUMBER() over(order by [pictures].[id] desc)as rownum,
--这个无效distinct [pictures].[id],
[pictures].[u_id],
[pictures].[title],
[pictures].[path],
[pictures].[postdatetime]
from [pictures]
join [picturestags] on [picturestags].[p_id]=[pictures].[id]
join [tags] on [tags].[id]=[picturestags].[t_id]
where [tags].[name] like @query)as pictures
Order by [postdatetime] desc
--try
;with f as
(
select * from
(select
ROW_NUMBER() over(order by [pictures].[id] desc)as rownum,
--这个无效distinct [pictures].[id],
[pictures].[u_id],
[pictures].[title],
[pictures].[path],
[pictures].[postdatetime]
from [pictures]
join [picturestags] on [picturestags].[p_id]=[pictures].[id]
join [tags] on [tags].[id]=[picturestags].[t_id]
where [tags].[name] like @query)as pictures
)
select * from f t where [rownum]=(select max([rownum]) from f where postdatetime=t.postdatetime)
------解决方案--------------------
group by
------解决方案--------------------
;with aaa as
(select
ROW_NUMBER() over(order by [pictures].[id] desc)as rownum,
[pictures].[u_id],
[pictures].[title],
[pictures].[path],
[pictures].[postdatetime]
from [pictures]
join [picturestags] on [picturestags].[p_id]=[pictures].[id]
join [tags] on [tags].[id]=[picturestags].[t_id]
where [tags].[name] like @query)
select * from aaa as a where not exists (select 1 from aaa
where aaa.u_id=a.u_id and aaa.title=a.title and aaa.[path]=a.[path] and aaa.postdatetime=a.postdatetime and aaa.rownum<a.rownum)