2010-07-10 27 views
4
insert into 
keyword_history (
    keyword_id, 
    searchengine, 
    location, 
    "4", 
    curdate() 
    ) 
select 
    keyword_id, 
    searchengine, 
    location 
from 
    keyword_history 
where 
    history_id = 21 

基本上,我想要做的是:我可以選擇插入到mysql但手動修改值嗎?

  1. 從表中選擇一行
  2. 再次插入,但這次與當前的日期和值「4」
+0

是否要插入與舊日期日期相同的日期,或者是否要更新以前的日期一? – 2010-07-10 00:29:42

回答

12

是的,你可以。你可能想嘗試,而不是以下:

INSERT INTO keyword_history 
(
    keyword_id, 
    searchengine, 
    location, 
    rec_date, 
    currentrank 
) 
SELECT keyword_id, 
     searchengine, 
     location, 
     curdate(), 
     '4' 
FROM keyword_history 
WHERE history_id = 21; 

編輯:更新字段名按下面的評論。

+0

我認爲你可能混淆了列名/值。 – 2010-07-10 00:33:31

+0

插入 keyword_history( keyword_id, 的搜索引擎, 位置, rec_date, currentrank ) 選擇 keyword_id, 的搜索引擎, 位置, CURDATE(), '4' 從 keyword_history 其中 history_id = 21 – vick 2010-07-10 00:33:55

+0

糟糕...固定。謝謝 :) – 2010-07-10 00:33:59

1

試試這個;看起來你是在不經意間將數值放入字段列表中...

insert into keyword_history 
    (keyword_id, searchengine, location, your_number_col, your_date_col) 
select keyword_id, searchengine, location, '4', curdate() 
from keyword_history 
where history_id = 21 
相關問題