Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.0k views
in Technique[技术] by (71.8m points)

sql - Get max value per day with the corresponding name

I have the following table:

day name val
12-01-2021 Een 1
11-01-2021 Twee 12
12-01-2021 Drie 0
12-01-2021 Twee 1
11-01-2021 Drie 19
11-01-2021 Een 11

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use distinct on:

select distinct on (day) t.*
from t
order by day, val desc;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...