这里要记录一个问题,在获取最后一次签到时间的时候,一开始的代码如下:
cr.execute("""select max(name) as name from hr_attendance where action in ('sign_in', 'sign_out') and employee_id = %s""",(employee_id,))
这个时候我要同时获取最后一次签到的动作类型,是sign_in或者sing_out,如果直接将代码改成:
cr.execute("""select max(name) as name,action from hr_attendance where action in ('sign_in', 'sign_out') and employee_id = %s group by action""",(employee_id,))
这样得到的结果是:
"2012-12-02 09:33:48";"sign_out"
"2012-12-02 09:24:03";"sign_in"
这就不是我想要的结果了,我需要的是9点33分的那个结果的action类型,也就是sign_out,而不是每一个action都获取一个最大值。
经过google,最终的代码如下:
select a.name,a.action from hr_attendance a inner join (select max(name) as maxf from hr_attendance) b on a.name=b.maxfwhere employee_id=1