Home > database >  A little complicated SQL, bosses help have a look.
A little complicated SQL, bosses help have a look.

Time:11-18

Process Flow sheet, field [Id, Name]
FlowDetail process details table field [Id, FlowId, Type SortId] FlowId is Flow Id, SortId is sequence Id, through sorting, in turn, find audit process node
FlowCheckUserInfo process audit staff table field [FlowDetailId, UserId]
FlowCheckInfo process audit record field [FlowId FlowDetailId, User, Status, remark] Status "" 0 means audit failure, 1 audit success
Order orders table field [Id, FlowId, BillNo]

Relationship is this: a process have N process details, details of a process may be N for examination and approval, if read my order table data pushed to it should audit staff?

CodePudding user response:

You don't have a flag field records the current backlog nodes? If not, then only by neither audit failure, also didn't review to determine the node for the complete success, and then take one of the serial number of minimum

 
SELECT ID, USERID, USER
The FROM
(SELECT A. *, D.U SERID, C.U SER, DENSE_RANK () OVER (PARTITION BY Anderson D ORDER BY SORTID) AS an RN
FROM the Order A
The JOIN FlowDetail B ON A.F LOWID=b. LOWID
The JOIN FlowCheckInfo C ON b. LOWID=C.F LOWID
The JOIN FlowCheckUserInfo D ON C.F lowDetailId=D.F lowDetailId
WHERE the Status NOT IN (' 1 ', '0')) AS A
WHERE an RN=1
GROUP BY ID, USERID, USER

CodePudding user response:

The select UserId
The from FlowCheckUserInfo f1
Left the join FlowDetail f2 on f1. FlowDetailId=f2. Id
Left the join Order o1 on o1. FlowId=f2. FlowId

  • Related