开发者

Can I select insert to mysql but modify values manually?

开发者 https://www.devze.com 2023-01-07 02:42 出处:网络
insert into keyword_history ( keyword_id, searchengine, location, \"4\", curdate() ) select keyword_id,
insert into 
 keyword_history (
   keyword_id, 
   searchengine, 
   location, 
   "4", 
   curdate()
   ) 
 select 
  keyword_id, 
  searchengine, 
  location 
 from 
  keyword_history 
 where 
  history_id = 21

Basically, what I'm开发者_JS百科 trying to do is :

  1. select a row from a table
  2. insert it again but this time with current date and the value "4"


Yes you can. You may want to try the following instead:

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;

EDIT: Updated field names as per comment below.


Try this; it seems you're putting values in your field list inadvertently...

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
0

精彩评论

暂无评论...
验证码 换一张
取 消