sql server - SQL combine multiple rows based on condition -


i have table of separate travel transactions of public transport users.
when travelers transit line line, generate 2 distinct transactions.
luckily source data contains shared key (uniquetravelid)

date     | mediumid | uniquetravelid | citime | cotime | cilocationid | colocationid   1-1-2015 | 1001     | 99             | 08:10  | 08:15  | 5001         | 5050   1-1-2015 | 1001     | 99             | 08:16  | 08:20  | 5001         | 5090   

i combine multiple distinct transactions based on earliest checkin , latest checkout time on same dates.

date     | mediumid | uniquetravelid | citime | cotime | cilocationid | colocationid   1-1-2015 | 1001     | 99             | 08:10  | 08:20  | 5001         | 5090   

i haven't tested ...

  1. create view grouped on date , uniquetravelid identifies unique journies date including min citime , max cotime exclude locations

  2. join view original table twice, 1 linking on min citime , uniquetravelid , other on max cotime , uniquetravelid , should give answer.

let me know if want more information


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -