Skip to content
Advertisement

Quartiles in Postgres

I have payment amounts like so –

How do I divide records like this into quartiles. It doesn’t have to be perfect. For example, the data in the question would transform like so –

Ids 124049 and 2323 are given the same quartile because those payment values are close together.

Advertisement

Answer

you can use ntile function :

db<>fiddle here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement