如何计算 SQLite 和 SUM 这些值的时差,按天分组? [英] How to calculate time difference in SQLite and SUM these values, grouping by day?

查看:33
本文介绍了如何计算 SQLite 和 SUM 这些值的时差,按天分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算 SQLite 中两个日期字段之间的总差异(它们被声明为 REAL).即datefield1 和 datefield2 并按天分组.

I want to calculate total difference between two date fields in SQLite (they are declared as REAL). I.E. datefield1 and datefield2 and group by day.

Datefield1 是登录日期,datefield2 是注销日期.每天,用户可以多次登录/注销.我想总结一个用户每天的登录时间(datefield2-datefield1).

Datefield1 is login date, datefield2 is logout date. Each day, user can login/logout several times. I want to sum up login time of a user (datefield2-datefield1) for each day.

推荐答案

SOLVED:

查询

select id, datetime(logindate), datetime(logoutdate), 
sum((julianday(logoutdate) - julianday(logindate)))
from MyTable GROUP BY strftime('%d', logindate);

这篇关于如何计算 SQLite 和 SUM 这些值的时差,按天分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆