(sql_i1, tb1)
return sql_query
sql = {'sel': 5, 'agg': 4, 'conds': [[3, 0, '59']]}
        agg_ops = ['', 'max', 'min', 'count', 'sum', 'avg']
        cond_ops = ['=', '>', '<', 'OP']

        Temporal as it can show only one-time conditioned case.
        sql_query: real sql_query
        sql_plus_query: More redable sql_query

        "PLUS" indicates, it deals with the some of db specific facts like PCODE <-> NAME
sql = {'sel': 5, 'agg': 4, 'conds': [[3, 0, '59']]}
        agg_ops = ['', 'max', 'min', 'count', 'sum', 'avg']
        cond_ops = ['=', '>', '<', 'OP']
sql = { sel : 5 agg : 4 conds : [[ 3 0 59 ]] } agg_ops = [ max min count sum avg ] cond_ops = [ = > < OP ]
def generate_sql_q1(sql_i1, tb1):
    """
        sql = {'sel': 5, 'agg': 4, 'conds': [[3, 0, '59']]}
        agg_ops = ['', 'max', 'min', 'count', 'sum', 'avg']
        cond_ops = ['=', '>', '<', 'OP']

        Temporal as it can show only one-time conditioned case.
        sql_query: real sql_query
        sql_plus_query: More redable sql_query

        "PLUS" indicates, it deals with the some of db specific facts like PCODE <-> NAME
    """
    agg_ops = ['', 'max', 'min', 'count', 'sum', 'avg']
    cond_ops = ['=', '>', '<', 'OP']

    headers = tb1["header"]
    # select_header = headers[sql['sel']].lower()
    # try:
    #     select_table = tb1["name"]
    # except:
    #     print(f"No table name while headers are {headers}")
    select_table = tb1["id"]

    select_agg = agg_ops[sql_i1['agg']]
    select_header = headers[sql_i1['sel']]
    sql_query_part1 = f'SELECT {select_agg}({select_header}) '


    where_num = len(sql_i1['conds'])
    if where_num == 0:
        sql_query_part2 = f'FROM {select_table}'
        # sql_plus_query_part2 = f'FROM {select_table}'

    else:
        sql_query_part2 = f'FROM {select_table} WHERE'
        # sql_plus_query_part2 = f'FROM {select_table_refined} WHERE'
        # ----------------------------------------------------------------------------------------------------------
        for i in range(where_num):
            # check 'OR'
            # number_of_sub_conds = len(sql['conds'][i])
            where_header_idx, where_op_idx, where_str = sql_i1['conds'][i]
            where_header = headers[where_header_idx]
            where_op = cond_ops[where_op_idx]
            if i > 0:
                sql_query_part2 += ' AND'
                # sql_plus_query_part2 += ' AND'

            sql_query_part2 += f" {where_header} {where_op} {where_str}"

    sql_query = sql_query_part1 + sql_query_part2
    # sql_plus_query = sql_plus_query_part1 + sql_plus_query_part2

    return sql_query
def generate_sql_q1 ( sql_i1 , tb1 ) : agg_ops = [ '' , 'max' , 'min' , 'count' , 'sum' , 'avg' ] cond_ops = [ '=' , '>' , '<' , 'OP' ] headers = tb1 [ "header" ] # select_header = headers[sql['sel']].lower() # try: #     select_table = tb1["name"] # except: #     print(f"No table name while headers are {headers}") select_table = tb1 [ "id" ] select_agg = agg_ops [ sql_i1 [ 'agg' ] ] select_header = headers [ sql_i1 [ 'sel' ] ] sql_query_part1 = f'SELECT {select_agg}({select_header}) ' where_num = len ( sql_i1 [ 'conds' ] ) if where_num == 0 : sql_query_part2 = f'FROM {select_table}' # sql_plus_query_part2 = f'FROM {select_table}' else : sql_query_part2 = f'FROM {select_table} WHERE' # sql_plus_query_part2 = f'FROM {select_table_refined} WHERE' # ---------------------------------------------------------------------------------------------------------- for i in range ( where_num ) : # check 'OR' # number_of_sub_conds = len(sql['conds'][i]) where_header_idx , where_op_idx , where_str = sql_i1 [ 'conds' ] [ i ] where_header = headers [ where_header_idx ] where_op = cond_ops [ where_op_idx ] if i > 0 : sql_query_part2 += ' AND' # sql_plus_query_part2 += ' AND' sql_query_part2 += f" {where_header} {where_op} {where_str}" sql_query = sql_query_part1 + sql_query_part2 # sql_plus_query = sql_plus_query_part1 + sql_plus_query_part2 return sql_query