MySQL Заявление Союза не работает, изо всех сил пытается понять, почему - PullRequest
0 голосов
/ 05 мая 2020

Я пытаюсь объединить две таблицы с помощью оператора UNION. Я сопоставляю столбцы обеих таблиц. Я не понимаю, в чем проблема.

Синтаксическая ошибка отсутствует.

ОЖИДАЕМЫЙ РЕЗУЛЬТАТ

Table B1:

id   Date            DR_code      DR_code     CR     CR_code
ob3  2019-12-31      B1           20000       0   
*then all values in table B1*

Table B2:

id   Date            DR_code      DR_code     CR     CR_code
ob4  2019-12-31      B2           1000       0   
*then all values in table B2*

Спасибо за любую помощь

MySQL вер. 14.14, расст. 5.7.23

# for loop below creates strings: B1 and B2
for bank in Bank_Account_Code:
    with engine.connect() as con:
        con.execute('''
        SELECT id, Date, DR_code, DR, CR, CR_code FROM '''+bank+'''
        UNION ALL
        SELECT id, Date, DR_code, DR, CR, CR_code FROM Opening_Balances
        WHERE DR_code="'''+bank+'''"
        ;''')
        con.execute('''
        SELECT id, Date, DR_code, DR, CR, CR_code FROM '''+bank+'''
        UNION ALL
        SELECT id, Date, DR_code, DR, CR, CR_code FROM Opening_Balances
        WHERE CR_code="'''+bank+'''"
        ORDER BY DATE
        ;''')

enter image description here

enter image description here

...