views:

30

answers:

1

I have a query that is producing something like this:

StartTimestamp  |  EndTimestamp
================================
100             | 450
--------------------------------
150             | 500

I'd like the result to also include the difference between EndTimestamp and StartTimestamp:

StartTimestamp  |  EndTimestamp  |  Difference
==============================================
100             | 450            | 350
----------------------------------------------
150             | 600            | 450

How do I do this in MySQL?

+1  A: 

If the table is named, say, t:

SELECT t.StartTimestamp, t.EndTimestamp, t.EndTimestamp - t.StartTimestamp AS Difference
FROM   &c

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.

Alex Martelli