1

だから私はこの2つのテーブルを持っています.operators_payments AS opにはデータが入力されていますが、支払い日が来るまでop.date_paidNULLになります。 NOW())に設定し、支払い完了のためにop.date_paid をpp.date_startedに設定します。示されているクエリは、これを行うために使用されます。すべて問題ありませんが、すべてのレコードが更新されると、レコードの 1 つと 1 つだけが異なる時間、具体的には2 番目のop.date_paidを取得します。一部の例 (1 つを除くすべてに設定された時間: 2012-07-05 17:28: 14、1 つに設定された時間: 2012-07-05 17:28: 02 )。

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              |                             |
+----------------+--------------+------+-----+-------------------+-----------------------------+
4

1 に答える 1

1

I have a suspicious eye toward that on update CURRENT TIMESTAMP clause on the date_started on payment_process... I'm not actually sure what it could be doing in this query, but you are updating that table in this query, and using that value. I also don't like the semantic discord of a column called date_started which has it's value changed on every update... but I don't know how it's used. I would evaluate if that clause is necessary on that column, and see if you get this strange behavior without it,

于 2012-07-05T22:22:08.857 に答える