Fandy Razzle
Fandy Razzle

Reputation: 33

postgresql how to get min and max value from specific range

I have this table of log finger print attendannce.

enter image description here

and i want to select the table with the result like this.

enter image description here

as you can see, in the mindailylog field, it contains the minumum date of that day, and the maxdailylog field value contains the max value of that day.

Upvotes: 0

Views: 1087

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269773

You can use window functions:

select t.*,
       min(waktuabsen) over (partition by userid, waktuabsen::date),
       max(waktuabsen) over (partition by userid, waktuabsen::date),
from t;

This does the minimum per user_id. If you want the overall minimum, just remove userid from the partition by.

Upvotes: 1

Related Questions