标签:
建表: create
table
tablename (id
int
identity(1,1),attachid
int
,
name
varchar
(10))
insert
into
tablename values
(23,
‘sss‘
)
insert
into
tablename
values
(33,
‘sdfs‘
)
insert
into
tablename
values
(33,
‘4434‘
)
insert
into
tablename
values
(45,
‘dsdsd‘
)
select
*
from
tablename as a
where
not
exists (
select
1
from
tablename
where
attachid=a.attachid
and
name
<a.
name
)
id attachid
name
----------- ----------- ----------
1 23 sss
3 33 4434
4 45 dsdsd
(select * from
( SELECT *,ROW_NUMBER() OVER(ORDER BY CompletedTime1 DESC) AS PagerAutoRowNumber
FROM WorkFlowTask
WHERE ReceiveID=‘00000000-0000-0000-0000-000000009667‘ AND [Status] IN(2,3) ) as a
where not exists --其实后面只是一个查询条件(包含子查询)
(select 1 from WorkFlowTask
where GroupID=a.GroupID and ReceiveTime>a.ReceiveTime and ReceiveID=‘00000000-0000-0000-0000-000000009667‘ AND [Status] IN(2,3)
)
标签:
原文地址:http://www.cnblogs.com/nihaoyueyue/p/5892369.html