def get_continuously_query_to_sql(query, trade_day):
    '''
    根据传入的查询对象和起始时间生成sql
    trade_day是要查询的交易日列表
    '''
    if query.limit_value:
        limit = min(FUNDAMENTAL_RESULT_LIMIT, query.limit_value)
    else:
        limit = FUNDAMENTAL_RESULT_LIMIT
    offset = query.offset_value
    query = query.limit(None).offset(None)

    from .fundamentals_tables_gen import (
        BalanceSheet, CashFlowStatement, FinancialIndicator,
    )

    def get_table_class(tablename):
        for t in (
            BalanceSheet, CashFlowStatement, FinancialIndicator,  # noqa
            IncomeStatementDay, StockValuation, BankIndicatorAcc,  # noqa
            SecurityIndicatorAcc, InsuranceIndicatorAcc  # noqa
        ):
            if t.__tablename__ == tablename:
                return t

    def get_tables_from_sql(sql):
        m = re.findall(
            r'cash_flow_statement|balance_sheet|financial_indicator|'
            r'income_statement|stock_valuation|bank_indicator_acc|security_indicator_acc|'
            r'insurance_indicator_acc', sql)
        return list(set(m))
    # 从query对象获取表对象
    tablenames = get_tables_from_sql(str(query.statement))
    tables = [get_table_class(name) for name in tablenames]
    valuation = StockValuation  # noqa
    query = query.filter(valuation.day.in_(trade_day))
    # 根据stock valuation 表的code和day字段筛选
    for table in tables:
        if table is valuation:  # noqa
            query = query.filter(valuation.code == table.code)
            query = query.filter(valuation.day >= table.periodStart)
            query = query.filter(valuation.day <= table.periodEnd)

    # 连表
    for table in tables[1:]:
        query = query.filter(table.code == tables[0].code)

    # 恢复 offset, limit
    query = query.limit(limit).offset(offset)
    sql = compile_query(query)
    # 默认添加查询code和day作为panel索引
    sql = sql.replace('SELECT ', 'SELECT DISTINCT stock_valuation.day AS day,stock_valuation.code as code, ')
    return sql
根据传入的查询对象和起始时间生成sql
trade_day是要查询的交易日列表
jqdatasdk/finance_service.py