Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8856867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:27:18+00:00 2026-06-14T14:27:18+00:00

There is a PostgreSQL SQL SELECT results. I need to divide rows into quintiles

  • 0

There is a PostgreSQL SQL SELECT results. I need to divide rows into quintiles and update quintil value to the specific row.

Is there some possibility to do this requirement in SELECT without need to do it in application? I would like to avoid situation when I need to select data to application and do the ranking out of PostgreSQL server.

Data example – first column is value, second column is quintil

4859 - 5
4569 - 5
4125 - 4
3986 - 4
3852 - 3
3562 - 3
3452 - 2
3269 - 2
3168 - 1
3058 - 1

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:27:19+00:00Added an answer on June 14, 2026 at 2:27 pm

    There is a window function called “ntile” to produce this: you give it a parameter specifying how many “tiles” the output it covers should be divided into (5 in this case).

    For example:

    select t.id, ntile(5) over (order by t.id)
    from t
    

    See window function tutorial for an introduction to window functions, and window functions for a list of the standard ones supplied.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simple alternative in PostgreSQL to this statement produced in Oracle? select
In PostgreSQL, there is this very useful string_agg function, that allows query like: SELECT
I am porting a database from SQL Server to PostgreSQL. Is there any alternative
I am using PostgreSQL 9.1 and need help with concatenating multiple rows in one.
I've converted a bunch of DML (INSERT/UPDATE/DELETE) queries from Oracle into PostgreSQL and now
Is there a way to disable the Postgresql translation of messages? I´m running my
Is there a way to speed up PostgreSQL's createdb command? Normally I wouldn't care,
Is there an existing function to replace accented characters with unadorned characters in PostgreSQL?
Apparently there is a database postgres that is created by default on each postgresql
Background In a PostgreSQL 9.0 database, there are various tables that have many-to-many relationships.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.