Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
770 B
2
Indexable
Never
-- Insert data into table1
INSERT INTO table1 (patient_id, patient_id2)
SELECT patient_id, patient_id2
FROM (
    SELECT patient_id, patient_id2, 
           ROW_NUMBER() OVER (ORDER BY patient_id) AS rn
    FROM your_table
) AS subquery
WHERE rn % 3 = 1;

-- Insert data into table2
INSERT INTO table2 (patient_id, patient_id2)
SELECT patient_id, patient_id2
FROM (
    SELECT patient_id, patient_id2, 
           ROW_NUMBER() OVER (ORDER BY patient_id) AS rn
    FROM your_table
) AS subquery
WHERE rn % 3 = 2;

-- Insert data into table3
INSERT INTO table3 (patient_id, patient_id2)
SELECT patient_id, patient_id2
FROM (
    SELECT patient_id, patient_id2, 
           ROW_NUMBER() OVER (ORDER BY patient_id) AS rn
    FROM your_table
) AS subquery
WHERE rn % 3 = 0;