sqlite3:near"(&#34 ;:语法错误 - python代码

时间:2015-01-11 16:15:56

标签: python sqlite

我收到此查询的语法错误,无法弄清楚我在这里犯了什么错误。

db = sqlite3.connect('C:\Users\Siva Sakthi Velan\Downloads\Intranet\mobiveil.db')
sql = """select cast(sum(datediff(second,0,Total_Hours))/3600 as varchar(12)) + ':' +right( '0' + cast(sum(datediff(second,0,Total_Hours))/60%60 as varchar(2)),2) +':' + right('0' + cast(sum(datediff(second,0,Total_Hours))%60 as varchar(2)),2) from  timesheet order by Date group by Task_Category where Date >=? and Date<=?"""
sq1 = db.execute(sql,(str(From),str(To)))

error: near "(": syntax error 

我该如何纠正?

1 个答案:

答案 0 :(得分:1)

您无法在SQLite中使用right();有no such function。请改用substr()

substr(...., -2)

获取最后两个字符。

您还需要修正wheregroup byorder by条款的顺序;这些有一个strict order

...
from timesheet
where Date >=? and Date<=?
group by Task_Category
order by Date

首先是WHERE,然后是GROUP BY,然后是ORDER BY