[英]How to write an SQL query comparing between two dates?
我為 Chartit 編寫了這段代碼,但我想要一個 SLQ 原始查詢:
def weather_chart_day_view(request):
patient=request.POST['patient']
id=patient_complete.objects.get(complite=patient).id
date=request.POST['date']
date1=request.POST['date1']
fsuivie_horraire.objects.raw('SELECT id,date_sh, avg(temp)as
temp, patient FROM
public.fsuivie_horraire where patient='+str(id)+' and date_sh >
'+date+' group by id,date_sh, patient;')} '''
我收到此錯誤:
ProgrammingError at /graphe/temperature_jour/ operator 不存在:date > integer LINE 1: ...lic.fsuivie_horraire wherepatient=3 and date_sh > 2020-03-...
正如其他人所提到的,您在這里很容易受到 SQL 注入攻擊。 然而,盡管如此。 我猜想問題出在你的date
字段上。 假設它是一個DateTime
字段,它將需要被引用。
嘗試將查詢更改為
'SELECT id, date_sh, avg(temp) as temp, patient FROM
public.fsuivie_horraire where patient='+str(id)+' and date_sh > \''+date+'\'
group by id, date_sh, patient;'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.