所以我有這樣的兩個表中,operators_payments歐普填充了數據,但op.date_paid將NULL,直到付款日到來時,當這種情況發生時, payment_process AS PP表用於支付初始化(pp.date_started設置爲NOW()),則支付完成的op.date_paid設置爲pp.date_started。所顯示的查詢,來做到這一點,一切都很好,但是當所有記錄更新,中記錄一個且只有一個得到op.date_paid以不同的時間,特別是秒部分如(時間設置爲除1之外的所有時間:2012-07-05 17:28:,時間設置爲1:2012-07-05 17:28:)。UPDATE JOIN,錯誤的數據插入
即時通訊使用Mysql 5.5,列具有相同的類型(TIMESTAMP)。 我需要這個,因爲我需要確切的日期是pp.date_started中的日期。
我的問題是,爲什麼會發生這種情況,我能做些什麼來預防這種情況?
UPDATE operators_payments AS op
JOIN payment_process AS pp
ON op.operator_id = pp.operator_id
AND pp.type = 0
AND pp.status = 1
SET op.date_paid = pp.date_started, pp.status = 2, pp.message=CONCAT(SUBSTRING_INDEX(message, '|', 1), '| was completed successfully!')
WHERE op.operator_id = {$this->operator_id}
AND op.date_paid IS NULL
AND op.date_end <= pp.date_accounted
+---------------+-----------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-----------------------+------+-----+-------------------+----------------+
| payment | int(10) unsigned | NO | PRI | NULL | auto_increment |
| operator_id | int(10) unsigned | NO | MUL | 0 | |
| date_paid | timestamp | YES | MUL | NULL | |
| date_start | timestamp | YES | | NULL | |
| date_end | timestamp | YES | MUL | NULL | |
| amount | decimal(6,4) unsigned | NO | | 0.0000 | |
+---------------+-----------------------+------+-----+-------------------+----------------+
+----------------+--------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+-------------------+-----------------------------+
| operator_id | int(11) | NO | PRI | NULL | |
| type | tinyint(4) | NO | PRI | NULL | |
| date_started | timestamp | YES | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| date_accounted | timestamp | YES | | NULL | |
| amount | decimal(6,4) | YES | | NULL | |
| status | tinyint(4) | YES | MUL | 0 | |
| message | varchar(255) | YES | | NULL | |
+----------------+--------------+------+-----+-------------------+-----------------------------+
謝謝,你真的在,我不會認爲這是問題。關於語義上的不和,這是來自我的新工作,就是這樣。 – Jmsegrev 2012-07-06 13:29:21