为什么有错误?
我的错误信息 (1064,“您的SQL语法有误;请查看与您的MySQL服务器版本相对应的手册,以获取在'201903附近使用的正确语法”),从律师y \ n以cnt \ n的身份访问,其中y.lawyer_status =' N'\ n'在第5行“)
@csrf_exempt
def answer_stats_excel(request):
if request.method == "POST":
year = request.POST.get("year")
month = request.POST.get("month")
print(year+month)
yearmonth = year+month
stats_data = Lawyer.objects.raw(
'''
select * from (
select
y.lawyer_name,
DATE_FORMAT(y.register_date, '%%Y-%%m-%%d') as reg_date,
(select count(counsel_answer_idx) from counsel_answer where lawyer_idx = y.lawyer_idx and DATE_FORMAT(register_date, '%%Y%%m') = '%s') as cnt
from lawyer y
where y.lawyer_status = 'N'
) A order by A.cnt desc ''', [year+month])
dataF = DataFrame(stats_data)
filename = '/folder/excel_.xlsx'
dataF.to_excel(filename, 'Sheet1', index=False, engine='xlsxwriter')
return redirect('/admin/visual/answer_stats')