数据库
首页 > 数据库> > 关于在sql中对字典中的key值引用

关于在sql中对字典中的key值引用

作者:互联网

目标是想通过字典工具输入时间范围获得sql表中对应的行

date = {'b':'2019-01-01','e':'2019-12-31'}
sql1 = """select id,t_player_order.player_id,order_id,money,DATE_FORMAT(t_player_order.handle_dt,'%Y-%m'),DATE_FORMAT(t_player.create_dt,'%Y-%m') from t_player_order left join t_player  
           on t_player_order.player_id = t_player.player_id WHERE handle_dt between '{b}' and '{e}' """.format(b=date.get('b'),e=date.get('e'))

    # wrong!!!
    # sql1 = """select id,t_player_order.player_id,order_id,money,DATE_FORMAT(t_player_order.handle_dt,'%Y-%m'),DATE_FORMAT(t_player.create_dt,'%Y-%m') from t_player_order left join t_player
    #            on t_player_order.player_id = t_player.player_id WHERE handle_dt between 'b' and 'e' """

cursor1.execute(sql1)

 

标签:FORMAT,id,player,key,sql,DATE,dt,order,字典
来源: https://www.cnblogs.com/bcattie-nicole/p/16527672.html