Two days before the project went live, I went through the code again, and I felt that there was a problem with the SQL logic, so I took it out and analyzed it, and there was a problem, and then recursive query was used and recorded.
basic structure
select * from table_name
start with id = ''
connect by prior id = preid
The id of this piece of data is the preid of the next piece of data. To traverse downward
, the keyword in can be used for id . The results of the prior keyword before and after = are different.
select j.userid, j.username, j.usercode
from XT_USER j, XT_USERROLE U
where J.USERID = U.USERID
AND U.ROLEID IN ('D5FCE584', 'DBC71B7B')
and j.deptid in
(select distinct o.organiseid
from xt_organise o
start with o.organiseid in
(select distinct z.zzid
from zldt_jf z
where FLOOR(TO_DATE(Z.JZ_DAY, 'YYYY-MM-DD') - SYSDATE) = 7)
connect by prior o.organiseid = o.preorganiseid)