Django选择查询时间差 [英] Django Select Query Time Diff

查看:205
本文介绍了Django选择查询时间差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在django中查询数据库表,其中包括以下列:

I am trying to query a database table in django with, among others, the following columns:

id | start_time | end_time

而不是获取两个单独的值,我可以直接在查询中获得差异?
有这样的效果:

Rather than getting the separate values for the two, can I just get the difference directly in a query? Something to this effect:

SELECT id, Diff(start_time, end_time) FROM myTable


推荐答案

QuerySet.extra() 将允许您为列指定任意表达式。请注意,结果将取决于DB。

QuerySet.extra() will allow you to specify arbitrary expressions for a column. Note that the result will be DB-dependent.

这篇关于Django选择查询时间差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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