如何获得2列之间的差异

编程入门 行业动态 更新时间:2024-10-27 11:21:10
本文介绍了如何获得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列之间的差异

本文发布于:2023-10-19 19:09:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508491.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   差异

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!