grand_total 필드가있는 'quot_items'라는 테이블이 있습니다. 이 구조가 있습니다
tender_id | grand_total
15001 100000
15002 250000
15003 1500000
16009 4500000
'category'필드가있는 'quotation'이라는 또 다른 테이블이 있습니다. 이 구조를 가지고 있습니다.
tender_id | category
15001 H
15002 E
15003 B
16009 A
iam이 시도하는 것은 특정 조건이있는 MYSQL에서 UPDATE 문이 필요하다는 것입니다.
[grand_total '] <'100000 ')이면 Category H (즉,'quot_items '테이블의 grand_total 값이 <100000이면 업데이트 테이블'quotation '범주 필드를'H '로 업데이트합니다.
([ 'grand_total']> = '100000') && ([ 'grand_total'] <= '200000')이면 카테고리 'G'.
([ 'grand_total']> '200000') && ([ 'grand_total'] <= '600000')이면 범주 'F'.
([ 'grand_total']> '600000') && ([ 'grand_total'] <= '1000000')이면 카테고리 'E'.
([ 'grand_total']> '1000000') && ([ 'grand_total'] <= '1500000')이면 카테고리 'D'.
더 많은 조건이 있습니다. 하나의 업데이트 문에서 DB를 업데이트 할 수 있도록 MYSQL에서이 작업을 수행하는 쿼리가 필요합니다. Pls 누구든지 나를 도울 수 있습니다.
나는 다음을 시도했다 :
UPDATE quotation INNER JOIN quotation_items ON quotation.tender_id = quotation_items.tender_id
SET quotation.category = (
CASE WHEN quotation_items.grand_total < 100000 then 'H'
WHEN quotation_items.grand_total >= 100000 && quotation_items.grand_total <= 200000 then 'G'
WHEN quotation_items.grand_total > 200000 && quotation_items.grand_total <= 600000 then 'F'
WHEN quotation_items.grand_total > 600000 && quotation_items.grand_total <= 1000000 then 'E'
WHEN quotation_items.grand_total > 1000000 && quotation_items.grand_total <= 1500000 then 'D'
END
);
이 시도:
UPDATE quotation t1
INNER JOIN quot_items t2
ON t1.tender_id = t2.tender_id
SET t1.category =
CASE WHEN t2.grand_total < 100000 THEN 'H'
WHEN grand_total >= 100000 AND grand_total <= 200000 THEN 'G'
WHEN grand_total > 200000 AND grand_total <= 600000 THEN 'F'
WHEN grand_total > 600000 AND grand_total <= 1000000 THEN 'E'
WHEN grand_total > 1000000 AND grand_total <= 1500000 THEN 'D'
ELSE t1.category
END
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다