只是無法圍繞這一個正確的語法包裹我的頭。下面是我的查詢,對我的子查詢進行簡單的英語解釋,並在我認爲我希望它執行的地方。MySQL INSERT/SELECT子查詢語法
mysql_query("INSERT INTO donations(
tid,
email,
amount,
ogrequest,
total
)
VALUES (
'".esc($p->ipn_data['txn_id'])."',
'".esc($p->ipn_data['pay_email'])."',
".(float)$amount.",
'".esc(http_build_query($_POST))."',
Here I want to select the row with the max date, get the value of the "total" column in that row, and add $amount to that value to form the new "total" for my newly inserted row.
)");
任何人都可以幫忙嗎?
你是對的。我這樣做的唯一原因是因爲我需要經常訪問它,並且想知道在數百行中不斷計算SUM的開銷。我想,不必遍歷所有這些行,我可以從最後一行獲得單個值,這對數據庫來說應該不那麼緊張。你會推薦什麼技術來緩存它? – Jon 2011-02-02 17:57:25