【发布时间】:2013-05-22 09:51:15
【问题描述】:
我需要编写 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我的代码有什么问题?
【问题讨论】:
-
您的栏目名称是年份?
-
没有列名是日期
-
你有什么数据库作为你的后端?
-
sqlite 数据库现在稍后我将更改为 mysql
-
@Lahiruzz 那你为什么要标记mysql?而且我认为 SQLite 没有
YEAR()功能。