-- Create a hypothetical table and insert 10 sample records
CREATE TABLE your_table (
patient_id INT,
patient_id2 INT
);
INSERT INTO your_table (patient_id, patient_id2)
VALUES
(1, 101),
(2, 102),
(3, 103),
(4, 104),
(5, 105),
(6, 106),
(7, 107),
(8, 108),
(9, 109),
(10, 110);
-- Create table1 with the same structure
CREATE TABLE table1 (
patient_id INT,
patient_id2 INT
);
-- Create table2 with the same structure
CREATE TABLE table2 (
patient_id INT,
patient_id2 INT
);
-- Create table3 with the same structure
CREATE TABLE table3 (
patient_id INT,
patient_id2 INT
);
-- Generate row numbers in a subquery
WITH NumberedRows AS (
SELECT
patient_id,
patient_id2,
ROW_NUMBER() OVER (ORDER BY patient_id) AS rn
FROM your_table
)
-- Insert data into table1
INSERT INTO table1 (patient_id, patient_id2)
SELECT patient_id, patient_id2
FROM NumberedRows
WHERE rn % 3 = 1;
-- Insert data into table2
INSERT INTO table2 (patient_id, patient_id2)
SELECT patient_id, patient_id2
FROM NumberedRows
WHERE rn % 3 = 2;
-- Insert data into table3
INSERT INTO table3 (patient_id, patient_id2)
SELECT patient_id, patient_id2
FROM NumberedRows
WHERE rn % 3 = 0;