question

hakimi avatar image
hakimi asked

need time different calculation

Dear All I have table that has name | flightdate| from | to | flight number | booking datetime| Name1 : 10/10/2013: london| frankfurt| 100| 05/10/2013 10:00pm Name2 : 10/10/2013: london| frankfurt| 100| 05/10/2013 11:00pm Name1 : 10/10/2013: london| frankfurt| 100| 02/11/2013 6:00pm how can i get number of rows that has flown same sector same details with small time differnet between first booking and the second booking. thank you Hakimi
sqltimecalculations
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
Something along these lines: SELECT * FROM myTable as mt JOIN (SELECT TOP(1) mt2.name, mt2.[booking datetime] FROM myTable as mt2 WHERE mt2.name = mt.name ORDER BY mt2.[booking datetime] DESC) as mtj ON mt.name = mtj.name and mt.[booking_datetime] = mtj.[booking datetime]; You may need to play around with it a little. CROSS APPLY could work too. It's similar to the versioned data queries [you can see here][1]. [1]: https://www.simple-talk.com/sql/database-administration/sql-strategies-for-versioned-data/
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.