34,587
社区成员
发帖
与我相关
我的任务
分享
with cte1
as
(
select id,listbh,[dealrq],[dealsj],xlbh from zzz
),
cte2
as
(
select id,listbh,[dealrq],[dealsj],xlbh from zzz
)
select * from cte1,cte2
where cte1.id=cte2.id-1
and cte1.listbh=cte2.listbh
and cte1.[dealrq]=cte2.[dealrq]
and convert(int,(SUBSTRING(cte2.dealsj,1,4)))-convert(int,(SUBSTRING(cte1.dealsj,1,4)))<=130
and cte1.xlbh<>cte2.xlbh
内连接语句
select * from zzz c
inner join zzz p
on c.id = p.id-1
and c.listbh=p.listbh
and c.[dealrq]=p.[dealrq]
and convert(int,(SUBSTRING(p.dealsj,1,4)))-convert(int,(SUBSTRING(c.dealsj,1,4)))<=130
and p.xlbh<>c.xlbh