insert中使用子查询

主要子查询返回的是一个字段即可:
INSERT INTO t_upsNode(

companyId, stateId, upsId, originalUpsName, isActivate, upsManufactId

, upsModelId, upsVersion, agentVersion, ip, PORT, mac, memo, capability

, configOutputPower, configInputVa, configOutputVolt, configInputFreq

, configOutputFreq, createTime, isMonitorService

)

VALUES (

1, 1, "no.01", "测试设备1", TRUE, 1

, (SELECT id upsModelId FROM t_upsModel WHERE CNName = "M9900"),"1.0"

, "1.0", "127.0.0.1", "8080", "123", "备注", 1.0, 1.0, 1.0, 1.0, 1.0, 1.0

, "2018-01-10 10:00:00", TRUE

)

批量写法:

INSERT INTO t_upsNode (companyId, stateId, upsId, originalUpsName, isActivate, upsManufactId

, upsModelId, upsVersion, agentVersion, ip, PORT, mac, memo, capability

, configOutputPower, configInputVa, configOutputVolt, configInputFreq

, configOutputFreq, createTime, isMonitorService)

VALUES

(1, 1, "no.01", "测试设备1", TRUE, 1

, (SELECT id upsModelId FROM t_upsModel WHERE CNName = "M9900"),"1.0"

, "1.0", "127.0.0.1", "8080", "123", "备注", 1.0, 1.0, 1.0, 1.0, 1.0, 1.0

, "2018-01-10 10:00:00", TRUE),

(1, 1, "no.01", "测试设备1", TRUE, 1

, (SELECT id upsModelId FROM t_upsModel WHERE CNName = "M9900"),"1.0"

, "1.0", "127.0.0.1", "8080", "123", "备注", 1.0, 1.0, 1.0, 1.0, 1.0, 1.0

, "2018-01-10 10:00:00", TRUE )

 

你可能感兴趣的:(insert中使用子查询)