这个怎么样?使用两个变量。
SQLFIDDLE演示
询问:
set @tot:=0;set @sup:=0;select x.id, x.supplier, x.ctotfrom (select id, supplier, qty,@tot:= (case when @sup = supplier then@tot + qty else qty end) as ctot,@sup:=supplierfrom demoorder by supplier asc, id desc) xwhere x.ctot >=5;| ID | SUPPLIER | CTOT |------------------------| 2 | 1 | 5 || 1 | 1 | 7 || 3 | 2 | 5 |



