I have table in MS Access 2010 with below sample data:
schedule_nr | part_number | name | date1 | date2 | difference|
------------|-------------|------|---------------|---------------|-----------|
12345 | 1 |Part1 |01-02-16 2:50 |01-02-16 2:50 | |
12345 | 2 |Part2 |01-02-16 2:54 |01-02-16 2:54 | |
12345 | 3 |Part3 |01-02-16 3:03 |01-02-16 3:03 | |
45678 | 1 |Part1 |02-02-16 2:15 |02-02-16 2:15 | |
45678 | 2 |Part2 |02-02-16 2:19 |02-02-16 2:19 | |
45678 | 3 |Part3 |02-02-16 2:27 |02-02-16 2:27 | |
23456 | 1 |Part1 |02-02-16 13:17 |02-02-16 13:17 | |
23456 | 2 |Part2 |02-02-16 13:21 |02-02-16 13:21 | |
23456 | 3 |Part3 |02-02-16 13:30 |02-02-16 13:30 | |
------------|-------------|------|---------------|---------------|-----------|
In column "difference" I need to have difference between date2 and date1 from previous row. From each part_number = 1 counting difference should be done from beginning. So the final table should look like below:
schedule_nr | part_number | name | date1 | date2 | difference|
------------|-------------|------|---------------|---------------|-----------|
12345 | 1 |Part1 |01-02-16 2:50 |01-02-16 2:50 |0:00:00 |
12345 | 2 |Part2 |01-02-16 2:54 |01-02-16 2:54 |0:04:00 |
12345 | 3 |Part3 |01-02-16 3:03 |01-02-16 3:03 |0:09:00 |
45678 | 1 |Part1 |02-02-16 2:15 |02-02-16 2:15 |0:00:00 |
45678 | 2 |Part2 |02-02-16 2:19 |02-02-16 2:19 |0:04:00 |
45678 | 3 |Part3 |02-02-16 2:27 |02-02-16 2:27 |0:08:00 |
23456 | 1 |Part1 |02-02-16 13:17 |02-02-16 13:17 |0:00:00 |
23456 | 2 |Part2 |02-02-16 13:21 |02-02-16 13:21 |0:04:00 |
23456 | 3 |Part3 |02-02-16 13:30 |02-02-16 13:30 |0:09:00 |
------------|-------------|------|---------------|---------------|-----------|
Is it possible to do it as one query in MS Access ?
Thnks everybody for help and hints. It looks like it works now. Thanks again.