Column names do not necessarily have to be the same, as long as you are listed in HH the list of columns to be inserted corresponds to list one by one of the selected columns in the Select from MM table, of course, the data types on both sides should be compatible.
Insert into HH (FIELDA,FIELDB,FIELDC) select Fieldx,fieldy,fieldz from mm
Copy Code code as follows:
---Update the data that does not exist in the metering point, transfer the information in the ledger to the metering point
Insert into metricpoints (METERID,METRICPOINTNAME,[DESCRIPTION],DEPARTMENTID,MEDIUMID)
(SELECT M.meterid,m.metricitems+m.installplace as M_metricpointname,m.metricitems,m.departmentid,m.mediumid
From Meters M WHERE does EXISTS (SELECT 1 from metricpoints where Metricpoints.meterid = M.meterid) and M.mediumid =2)
Fame: a,b, all tables
Copy Code code as follows:
--b table exists (same as two table structure)
INSERT INTO b select * from a
If the two tables are only partially (fields) identical, then
Copy Code code as follows:
Insert into B (col1,col2,col3,col4,...) Select Col1,col2,col3,col4,... from a where ...
Insert Table A into table B.
Copy Code code as follows:
--b table does not exist
SELECT * into B from a
//
Select (Field 1, Field 2, ...) into B from