【问题标题】:Insert only two columns data from another table and leave the rest with default values只插入另一个表中的两列数据,其余的保留默认值
【发布时间】:2020-11-28 11:29:37
【问题描述】:

MySql 表有四列。如何从另一个表中插入两列数据,其他两列手动填写。

insert into faulthistory (D_ID,D_IP,D_Status,Date_time) 
select IP_ID,D_IP from device where D_IP='192.168.1.1', '0',now();

【问题讨论】:

  • 不可能。您需要使用 2 个插入语句

标签: mysql sql datatable sql-insert sql-query-store


【解决方案1】:

将“手动”值放入选择列表中:

insert into faulthistory
 (D_ID,D_IP,D_Status,Date_time) 
select IP_ID, D_IP, '0', now() from device where D_IP='192.168.1.1'

您也可以为这两列定义默认值。

【讨论】:

    猜你喜欢
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    相关资源
    最近更新 更多