0
값이있는 두 개의 테이블과 사용자가있는 두 개의 테이블이 있습니다.두 테이블의 날짜를 비교하는 위치 업데이트
내 Table_1.value
을 a
으로 업데이트하고 싶습니다. 여기 내 Table_1.date < user_table.date
은 주어진 user_id
입니다. 특정 사용자가 where table1.user_id = 1
또는 ID를 추가하려면
update table1 inner join user_table
on (table1.user_id = user_table.user_id
and table1.date < user_table.date)
set table1.value = 'a'
:
Table_1
|user_id | value | date |
|--------|-------|------------|
| 1 | f | 2013-12-11 |
|--------|-------|------------|
| 2 | k | 2013-12-05 |
|--------|-------|------------|
| 3 | l | 2013-12-01 |
|--------|-------|------------|
| 4 | n | 2013-11-09 |
|--------|-------|------------|
| 4 | a | 2012-10-11 |
|--------|-------|------------|
| 2 | v | 2013-11-07 |
|--------|-------|------------|
| 1 | o | 2013-12-10 |
|--------|-------|------------|
| 3 | p | 2013-11-15 |
user_table
|user_id | date |
|--------|------------|
| 1 | 2013-12-15 |
|--------|------------|
| 2 | 2013-11-03 |
|--------|------------|
| 3 | 2013-12-11 |
|--------|------------|
| 4 | 2013-12-09 |
감사합니다. 나는'Table_3'의 값을'SET'하려고 시도했다.'Column not found : 1054 Unknown column Table_1.user_id on on clause'을 던졌습니다. 나는'UPDATE table_1, table_3 inner join user_table을 (table1.user_id = user_table.user_id 및 table1.date
Wistar
내 편집 됨 대답. 그것이 맞는 지보십시오. –
당신의 대답은 옳았습니다, 나는 내부 결합이 끝난 후에 Table_3을 넣을 필요가있었습니다. 감사합니다 – Wistar