我可以选择插入到mysql但手动修改值吗?

时间:2010-07-10 00:26:41

标签: mysql

insert into 
 keyword_history (
   keyword_id, 
   searchengine, 
   location, 
   "4", 
   curdate()
   ) 
 select 
  keyword_id, 
  searchengine, 
  location 
 from 
  keyword_history 
 where 
  history_id = 21

基本上,我要做的是:

  1. 从表中选择一行
  2. 再次插入,但这次是当前日期和值“4”

2 个答案:

答案 0 :(得分: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;

编辑:根据以下评论更新了字段名称。

答案 1 :(得分: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