假设您有一个字段来通过唯一的 id ( id_student
) 来识别每个学生,这里有一个便宜的替代方案:
CREATE OR REPLACE VIEW v_student_payment AS
SELECT 0 AS db, payment, id_student FROM database-0
UNION
SELECT 1 AS db, payment, id_student FROM database-1
UNION
SELECT 2 AS db, payment, id_student FROM database-2
UNION
SELECT 3 AS db, payment, id_student FROM database-3
/* here you have to add all databases you're using. There's a little maintenance cost, for if one day there's a new database to be created this view would have to be modified */
;
SELECT
original_student,
Other_student,
month,
v.payment
FROM
student s
JOIN v_student_payment v ON v.id_student = s.id_student AND v.db = SUBSTRING(other_student,3,1)