path
의 해시 및 parType 열을 동일한 테이블의 데이터로 업데이트하려고합니다. 나는 대답을 다음 SQL에서 그렇게 할 수는 있지만, 업데이트는 실패 할 것으로 보인다.동일한 테이블의 데이터로 테이블 업데이트
해시 = 0 및 parType = 0 인 모든 행을 동일한 행 ID 및 parType = 해당 행의 상위 ID의 유형 값으로 업데이트합니다.
원하는 결과가 표시되면 이해할 수 있습니다.
도와 주시겠습니까? 제 SQL은 신경 쓰지 마세요.
는 SQL
update path t join(
select t1.id, t1.type, t2.parent from path t1, path t2 where t1.parent = t2.id;
) as p on p.id=t.id set hash = t1.id and parType = t1.type;
업데이트하기 전에
"id" "type" "parent" "hash" "parType"
"1" "0" "0" "0" "0"
"2" "2" "1" "0" "0"
"3" "3" "2" "0" "0"
"4" "4" "3" "0" "0"
원하는 결과
"id" "type" "parent" "hash" "parType" //parType = the type of the parent
"1" "0" "0" "1" "0"
"2" "2" "1" "2" "0"
"3" "3" "2" "3" "2" -> This is value from the parents type
"4" "4" "3" "4" "3"
편집 -이 작동하지만, 나는 아직도 그것이
update path a join(
select t1.id as hash, t2.type as parType from path t1 inner join path t2 on t1.parent = t2.id
) b on a.id=b.hash set a.hash = b.hash , a.parType = b.parType;
당신이 어떤 오류 메시지가 무엇입니까? – Martao
오류 메시지가 없습니다. 아무것도 업데이트되지 않습니다. – jmenezes
왜 두 SQL 쿼리? – sarwar026