← 返回题库
初级

查询某账户的全部交易流水

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    offices_csv = open_url("https://data.zuihe.com/dbd/core/state_02/offices.csv").read()
    staff_csv = open_url("https://data.zuihe.com/dbd/core/state_02/staff.csv").read()
    savings_products_csv = open_url("https://data.zuihe.com/dbd/core/state_02/savings_products.csv").read()
    clients_csv = open_url("https://data.zuihe.com/dbd/core/state_02/clients.csv").read()
    savings_accounts_csv = open_url("https://data.zuihe.com/dbd/core/state_02/savings_accounts.csv").read()
    savings_account_transactions_csv = open_url("https://data.zuihe.com/dbd/core/state_02/savings_account_transactions.csv").read()
    import sqlite3
    import pandas as pd
    from io import StringIO

    conn = sqlite3.connect(':memory:')
    pd.read_csv(StringIO(savings_account_transactions_csv)).to_sql('savings_account_transactions', conn, index=False, if_exists='replace')

    result = pd.read_sql_query("""
        SELECT transaction_type, amount, running_balance, transaction_date, description
        FROM savings_account_transactions
        WHERE account_id = 1
        ORDER BY transaction_date, id
    """, conn)
    print(result.to_string(index=False))
    conn.close()

示例

输入
solve()
期望输出
transaction_type   amount  running_balance transaction_date description
         DEPOSIT 52000.00         52000.00       2026-06-03      首次开户存款
      WITHDRAWAL  5000.00         47000.00       2026-06-10       ATM取款
         DEPOSIT 10000.00         57000.00       2026-06-15          存款
      WITHDRAWAL  2000.00         55000.00       2026-06-23          支付
        INTEREST    16.03         55016.03       2026-06-30      6月活期利息
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码