我需要编写 django 原始查询来过滤年份和月份。为此,我尝试了以下代码。
cursor = connection.cursor()
cursor.execute('SELECT SUM(work_time) AS sum FROM structure_tracking_details WHERE employee_id = %s AND tree_id=%s AND project_structure=%s AND year(date)=%s AND month(date)=%s GROUP BY project_structure ', [employee_id,tree_id,project_structure,select_year,select_month] )
sum1=str(cursor.fetchone())
但它告诉no such function: year
我的代码有什么问题?