Django中原生sql语句查询的方法
sql = “SELECT count(*) from main_infohash”
sql = “select rows from table_rows where DATE_FORMAT(dt,’%Y%m%d’)=‘20181208’”
with connections[“update”].cursor() as c:
c.execute(sql)
totalinfo = c.fetchone()
增加模型类的方式
1、新增模型类、
2、totalinfo = Rows.objects.all().aggregate(Sum(“rows”))
infohashes = Rows.objects.filter(dt__range=[dtbegin, dtend]).values(‘dt’,‘rows’)