如何获得2列之间的差异 [英] How to get difference between 2 columns
本文介绍了如何获得2列之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询正在生成类似这样的内容:
I have a query that is producing something like this:
StartTimestamp | EndTimestamp
================================
100 | 450
--------------------------------
150 | 500
我希望结果还包括EndTimestamp和StartTimestamp之间的差异:
I'd like the result to also include the difference between EndTimestamp and StartTimestamp:
StartTimestamp | EndTimestamp | Difference
==============================================
100 | 450 | 350
----------------------------------------------
150 | 600 | 450
如何在MySQL中做到这一点?
How do I do this in MySQL?
推荐答案
如果表被命名为t
:
SELECT t.StartTimestamp, t.EndTimestamp, t.EndTimestamp - t.StartTimestamp AS Difference
FROM &c
当然,如果未修饰的名称StartTimestamp
和EndTimestamp
在其余查询的上下文中是明确的,则不需要在选择列中使用t.
部分.
Of course, you don't need the t.
parts in the select's columns if the undecorated names StartTimestamp
and EndTimestamp
are unambiguous in the context of the rest of your query.
这篇关于如何获得2列之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文