正经问题: SQL 语言

stored procedure with a cursor.
 
修改以后测试过的

WITH LR AS
(select LC.id,LC.dt
from LeaveCountry LC,
(select id,count(*)
from LeaveCountry
where dt<sysdate and dt>sysdate-730
group by id
having count(*)>=4) LI
where LC.id=LI.id
)
select LC.id,min(dt) dt
from LeaveCountry LC,
(select id
from LR
minus
select distinct a.id
from LR a, LR b
where a.id=b.id
and a.dt<>b.dt
and abs(a.dt-b.dt)<30
) LI
where LC.id=LI.id
group by LC.id
 
楼主年薪30万没问题了。
 
这不是程序,只是一小段sql语句而已,也许LZ是想集思广益.
 
WITH LR AS
(select LC.id,LC.date
from LeaveCountry LC,
(select id,count(*)
from LeaveCountry
where date between sysdate and sysdate-730
group by id
having count(*)>=4) LI
where LC.id=LI.id
)
select id,date
from LR
minus
select distinct a.id,a.date
from LR a, LR b
where a.id=b.id
and a.date<>b.date
and abs(a.date-b.date)<30

没测试过,只是大概思路.

谢谢。对不起,要增加难度了。如果一个人多次满足以上条件地话, 需要第一次满足条件的时间,以后再满足条件不管了。
 
谢谢。对不起,要增加难度了。如果一个人多次满足以上条件地话, 需要第一次满足条件的时间,以后再满足条件不管了。
楼主年薪30万没问题了。

我怎么木想到是丫的马甲呢?:blowzy: -- 老何?
 
修改以后测试过的:

WITH LR AS
(select LC.id,LC.dt
from LeaveCountry LC,
(select id,count(*)
from LeaveCountry
where dt<sysdate and dt>sysdate-730
group by id
having count(*)>=4) LI
where LC.id=LI.id
)
select LC.id,min(dt) dt
from LeaveCountry LC,
(select id
from LR
minus
select distinct a.id
from LR a, LR b
where a.id=b.id
and a.dt<>b.dt
and abs(a.dt-b.dt)<30
) LI
where LC.id=LI.id
group by LC.id 0

这方法很笨,如果表的数据量大可能需要运行比较长的时间.前面有人提到用存储过程也许会好一些.
 
眼看着又是一个坑,都进去吧。
 
什么坑啊!他自己喝着咖啡,其他人为他写码子。
 
这个人,上次不是挖坑,说“他”是小三,怀孕了,男朋友还没离婚的那个么?

这次不是坑?
 
这个人,上次不是挖坑,说“他”是小三,怀孕了,男朋友还没离婚的那个么?

这次不是坑?

美国朋友记忆真好。 :cool::p
 
楼主是给移民局干康踹克特的吗?多少钱一小时?:D
 
后退
顶部