이 문제를 해결하려면 함수 또는 트리거가 필요합니까 ??다른 테이블의 같은 열이 변경된 경우 열을 업데이트하는 방법 (postgresql)
customer_details :::
custid name creditid
----------------------------
2 a 1
3 b 2
4 c 3
BALANCE_AMOUNT :::
creditid credit_type balance
-----------------------------------
1 rent 1000
1 transport 2000
1 food 1000
1 fruits 1500
2 rent 1500
2 transport 1020
2 food 1200
2 fruits 1000
3 transport 1600
3 rent 2000
3 food 1540
3 fruits 1560
Pay_the_loan :::
creditid credit_type Pay status
---------------------------------------------
1 rent 500 null
2 fruits 600 null
3 transport 400 null
1 fruits 500 null
나는 특정 ok
에 대한 pay_the_loan table
에서 status
열을 업데이트되면 creditid
i 전화부 ..
then
그것이 BALANCE_AMOUNT 테이블에 balance
열의 양을 deduct
한다 (갱신 pay_the_loan 세트 상태 = creditid = 2 여기서 '확인')과이 업데이트되어야 즉 . (BALANCE_AMOUNT 테이블 1000-600 = 400
는 where
balance_amount.credit_type = 과일과 균형 양 테이블에서 creditid = 2)
가능한 포스트 나에게 Function
또는 Trigger
이 프로를 해결하기 위해 흠?
'1)'업데이트 조건은 언제 정의해야합니까? '2)'는 실제 update 문을 정의합니다 : 무엇을 변경해야하며, 어떻게해야합니까? '3)''2'를 함수로,'1'을 트리거로 변환합니다. '4)'이익!. '0)'테이블에 PGs/FKs가 필요합니다. – wildplasser
좋아, 이걸 더 잘 이해할 수있는 이런 예를 들고 갈거야 !! 문제는 @ wildplasser – 09Q71AO534