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

  • SEARCH
  • Home
  • 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 127133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:25:41+00:00 2026-05-11T05:25:41+00:00

Can someone please explain what the partition by keyword does and give a simple

  • 0

Can someone please explain what the partition by keyword does and give a simple example of it in action, as well as why one would want to use it? I have a SQL query written by someone else and I’m trying to figure out what it does.

An example of partition by:

SELECT empno, deptno, COUNT(*)  OVER (PARTITION BY deptno) DEPT_COUNT FROM emp 

The examples I’ve seen online seem a bit too in-depth.

  • 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. 2026-05-11T05:25:42+00:00Added an answer on May 11, 2026 at 5:25 am

    The PARTITION BY clause sets the range of records that will be used for each ‘GROUP’ within the OVER clause.

    In your example SQL, DEPT_COUNT will return the number of employees within that department for every employee record. (It is as if you’re de-nomalising the emp table; you still return every record in the emp table.)

    emp_no  dept_no  DEPT_COUNT 1       10       3 2       10       3 3       10       3 <- three because there are three 'dept_no = 10' records 4       20       2 5       20       2 <- two because there are two 'dept_no = 20' records 

    If there was another column (e.g., state) then you could count how many departments in that State.

    It is like getting the results of a GROUP BY (SUM, AVG, etc.) without the aggregating the result set (i.e. removing matching records).

    It is useful when you use the LAST OVER or MIN OVER functions to get, for example, the lowest and highest salary in the department and then use that in a calculation against this records salary without a sub select, which is much faster.

    Read the linked AskTom article for further details.

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

Sidebar

Related Questions

Can someone please explain with example that I can understand about the difference between
Can someone please explain to me how does Java garbage collector realize those memory
Can someone please explain or give some resources on how function composition works in
Can someone please explain to me why this simple assignment doesn't work. Here is
can someone please explain to me the following JavaScript design pattern example and what
Can someone please explain to me in simple English how an index on a
Can someone please explain why this JavaScript code outputs zero instead of one? Also,
Can someone please explain to me what parsing XML means? And what does an
Can someone please explain in simple terms how the AND, SHL and CMP commands
Can someone please explain to me why does COMMIT in this function returns EXCEPTION

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.