简体   繁体   中英

Insert data from one database table to another database table in the same server

I wrote this query using MYSQL work bench for insert data into one database to another database, but it doesn't work,can you help me to solve this problem

USE att2000;

create trigger trgAfterInsert after insert on CHECKINOUT for each row

INSERT INTO orangehrm_mysql.ohrm_attendance_record(employee_id,punch_in_utc_time) values(USERID,CHECKTIME);
SELECT 
    checkinout.USERID, checkinout.CHECKTIME
FROM
    CHECKINOUT
WHERE
HOUR(CHECKTIME) < 12;



INSERT INTO orangehrm_mysql.ohrm_attendance_record(employee_id,punch_out_user_time) values(USERID,CHECKTIME);
SELECT 
    checkinout.USERID, checkinout.CHECKTIME
FROM
    CHECKINOUT
WHERE
HOUR(CHECKTIME) >= 12;

Try without values

 INSERT INTO orangehrm_mysql.ohrm_attendance_record(employee_id,punch_in_utc_time) 
 (    
    SELECT 
        checkinout.USERID, checkinout.CHECKTIME
    FROM
        CHECKINOUT
    WHERE
    HOUR(CHECKTIME) < 12
 );



INSERT INTO orangehrm_mysql.ohrm_attendance_record(employee_id,punch_out_user_time) 
(
    SELECT 
        checkinout.USERID, checkinout.CHECKTIME
    FROM
        CHECKINOUT
    WHERE
    HOUR(CHECKTIME) >= 12
);

here you go:

INSERT INTO orangehrm_mysql.ohrm_attendance_record(employee_id,punch_in_utc_time) 
    (
       SELECT co.USERID, co.CHECKTIME
       FROM att2000.CHECKINOUT co
       WHERE HOUR(co.CHECKTIME) < 12
    );



INSERT INTO orangehrm_mysql.ohrm_attendance_record(employee_id,punch_out_user_time) 
    (
        SELECT co.USERID, co.CHECKTIME
        FROM att2000.CHECKINOUT co
        WHERE HOUR(co.CHECKTIME) >= 12
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM