我有点新的阅读存储过程。
我在想,如果这在mysql的存储过程中是可行的。
我有顺序的审批程序叫step。已批准的列;1为“是”,0为否。
基本上,我有第一步来3..in我的批准顺序。如果步骤1批准状态为0,则他将是第一个批准或查看表的人。如果步骤1批准为1。则步骤2现在可以看到表。
交易步骤表:
id transaction_id approver_id step approved
1 1 1 1 1
2 1 2 2 0
3 1 3 3 0
4 2 3 1 1
5 2 1 2 1
6 2 2 3 0
7 3 2 1 0
8 3 3 2 0
9 3 1 3 0
10 4 1 1 1
11 4 3 2 0
12 4 2 3 0示例,如果我的批准id =2
在我看来:我只能看到所有的下一个批准。
id transaction_id approver_id step approved
2 1 2 2 0
6 2 2 3 0
7 3 2 1 0如果可能的话请告诉我。谢谢
发布于 2014-12-01 02:57:54
如果我正确理解,您需要的行是每个事务的第一个未批准的行,审批者为2。
试试这个:
select ts.*
from transactionsteps ts join
(select transaction_id, min(step) as minstep
from transactionsteps
where approved = 0
group by transaction_id
) t
on ts.transaction_id = t.transaction_id and
ts.step = t.minstep
where approver_id = 2;https://stackoverflow.com/questions/27220966
复制相似问题