mardi 3 mars 2015

SQLite Select whichever column is greater

I'm really a novice at SQLite, so thanks in advance for any help.


I have a table with two timestamp columns, one is a start time and the other is an end time. I want to select the which ever column is greater for each row. (end time is zero for unfinished tasks)


I think I need to use a CASE expression but I just can't figure this one out.


Here is a select statement I tried that threw an exception, but shows what I'm going for.



SELECT _id, vin, command_id, CASE WHEN end_timestamp >= start_timestamp THEN end_timestamp ELSE start_timestamp, status
FROM reflash_commands ORDER BY start_timestamp DESC

Aucun commentaire:

Enregistrer un commentaire