Quantcast
Channel: Question and Answer » postgresql
Viewing all articles
Browse latest Browse all 1138

How to calculate shift hours in postgres?

$
0
0

I have table like below where (I=In) and (O=Out):


id | date | time | status | employee_id
----+------------+----------+--------+-------------
1 | 2015-07-01 | 11:00:00 | O | 1
2 | 2015-07-01 | 08:00:00 | I | 1
3 | 2015-07-01 | 16:00:00 | O | 1
4 | 2015-07-01 | 12:00:00 | I | 1
5 | 2015-07-02 | 16:30:00 | O | 1
6 | 2015-07-02 | 10:12:00 | I | 1

I want to calculate attendance grouped by date, employee_id and with shift hours like below:


date | employee_id | min | max | delta
------------+-------------+----------+----------+----------
2015-07-01 | 1 | 08:00:00 | 16:30:00 | 07:00:00 <--(shift)
2015-07-02 | 1 | 10:12:00 | 16:30:00 | 06:18:00

I don’t know if it can be possible to do it in postgresql.

Appreciate your support and help.


Viewing all articles
Browse latest Browse all 1138

Latest Images

Trending Articles



Latest Images