모든 b.quantityOrdered를 반복하고 d.quantityInStock에서 해당 금액을 뺀 업데이트 쿼리가 필요합니다.상태가 바뀔 때 주문 수량으로 주문 수량과 함께 수량을 업데이트하는 sql 쿼리
select
d.productCode as prod,
b.quantityOrdered as qtyO,
d.quantityInStock as qtyIS
from orders a
left join orderdetails b on a.orderNumber=b.orderNumber
left join products d on b.productCode=d.productCode
where a.status=6 and a.invoiceStatus=4
order by 1 asc
그 결과는 : :이 SQL 루프는 내가 업데이트가 필요한 정확하게 보여줍니다
prod qtyO qtyIS
104 19 110
104 4 110
104 20 110
105 10 20
105 15 20
105 24 20
더 나은, 나는 MySQL을 DB에 함수를 만들 수 있다면 그렇게 할 때 5에서 a.status 변경 ~ 6,이 업데이트 함수는 orderdetails 테이블을 반복하고 quantityinstock에서 수량을 뺍니다.
아니면이 작업을 수행하는 PHP 함수일까요?
[트리거] (http://dev.mysql.com/doc/refman/5.0/en/triggers.html)를 찾으십니까? – JDB