mysql加入时间戳sql语句,SQL插入时间戳问题
我試圖從我的user表中的兩列(user_id,team_id)中插入值到company_team的結表。但是,我通過兩次不同的嘗試將created_at和updated_at列的值插入到company_team中,并且不知道如何處理它們。SQL插入時間戳問題
在第一次嘗試,我只是想與從user表中的等價字段中的值更新兩個領域:(注列在兩個表是DATETIME)
INSERT INTO `company_team` (`created_at`,`updated_at`,`user_id`, `company_id`)
SELECT `user_id`, `company_id`, `created_at`, `updated_at`
FROM `user` AS `u`
WHERE `u`.`company_id` IS NOT NULL;
錯誤:
Incorrect datetime value: '1' for column 'created_at' at row 1
然后我試圖只用在創建記錄當前的日期/時間:
INSERT INTO `company_team` (NOW(),NOW(),`user_id`, `company_id`)
SELECT `user_id`, `company_id`, `created_at`, `updated_at`
FROM `user` AS `u`
WHERE `u`.`company_id` IS NOT NULL;
錯誤:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOW(),NOW(),`user_id`, `organization_id`)
SELECT `user_id`, `company_id`, `' at line 1
2017-04-07
cphill
總結
以上是生活随笔為你收集整理的mysql加入时间戳sql语句,SQL插入时间戳问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 算命
- 下一篇: 国内主流的ERP软件大盘点