Find Quarter from Month in Oracle SQL with Real Case Examples

Use Extracted Month to Find Quarter of the Year in Oracle SQL

There is a moment in every analyst’s journey when a simple date column refuses to cooperate. You stare at it, knowing the answer is somewhere inside those numbers, tucked between days and years. In Oracle SQL, dates carry more stories than we notice, and extracting a month is the first step to revealing those stories.

When I first learned this, I was working with a dataset where hiring patterns changed quarter by quarter. Managers wanted clarity. HR wanted trends. And I wanted a clean query that could explain the hiring cycle without making the database sweat. This is where the combination of EXTRACT, quarters, and a bit of SQL logic came together.

Table of Contents

How to Extract a Month from a Date

Think of dates as onions. Peel them layer by layer, and each layer tells a new truth. Oracle gives us a precise knife: EXTRACT. Whenever you want the month number from a timestamp or date, this one line gets you there.

SELECT EXTRACT(MONTH FROM hire_date) AS hire_month
FROM employees;

This returns values from 1 to 12. Simple, readable, and perfect for downstream logic. The moment you extract the month, the data feels lighter and easier to shape.

Converting Month into Quarter

Life becomes smoother when you group months into quarters, especially in business reporting. We often say “teen ka tadka,” meaning magic happens when things are grouped in three. Months behave the same way.

Using a CASE statement is the cleanest method:

SELECT
  EXTRACT(MONTH FROM hire_date) AS hire_month,
  CASE
    WHEN EXTRACT(MONTH FROM hire_date) BETWEEN 1 AND 3 THEN 'Q1'
    WHEN EXTRACT(MONTH FROM hire_date) BETWEEN 4 AND 6 THEN 'Q2'
    WHEN EXTRACT(MONTH FROM hire_date) BETWEEN 7 AND 9 THEN 'Q3'
    ELSE 'Q4'
  END AS hire_quarter
FROM employees;

This helps you build quarterly summaries, performance dashboards, or trend charts. A month feels like a single story; quarters feel like a chapter.

How Many Employees Were Hired in a Quarter

Now comes the real-world question: how many employees joined the company in a specific quarter? This is where grouping and filtering come together. I often use this technique when analysing workforce expansion or seasonal hiring trends.

SELECT
  CASE
    WHEN EXTRACT(MONTH FROM hire_date) BETWEEN 1 AND 3 THEN 'Q1'
    WHEN EXTRACT(MONTH FROM hire_date) BETWEEN 4 AND 6 THEN 'Q2'
    WHEN EXTRACT(MONTH FROM hire_date) BETWEEN 7 AND 9 THEN 'Q3'
    ELSE 'Q4'
  END AS hire_quarter,
  COUNT(*) AS total_hired
FROM employees
WHERE EXTRACT(YEAR FROM hire_date) = 2024
GROUP BY
  CASE
    WHEN EXTRACT(MONTH FROM hire_date) BETWEEN 1 AND 3 THEN 'Q1'
    WHEN EXTRACT(MONTH FROM hire_date) BETWEEN 4 AND 6 THEN 'Q2'
    WHEN EXTRACT(MONTH FROM hire_date) BETWEEN 7 AND 9 THEN 'Q3'
    ELSE 'Q4'
  END
ORDER BY hire_quarter;

This gives a clean summary. Managers understand it instantly, and dashboards love it.

CASE vs DECODE for Quarter Logic

Some developers prefer DECODE because it looks compact. But DECODE wasn’t designed for range conditions. You can still force it, but it becomes messy and hard to maintain.

Here is how DECODE would look if you try to assign quarters:

SELECT
  DECODE(
    TRUNC((EXTRACT(MONTH FROM hire_date) - 1) / 3) + 1,
    1, 'Q1',
    2, 'Q2',
    3, 'Q3',
    4, 'Q4'
  ) AS hire_quarter
FROM employees;

This works mathematically, but it loses readability. In analytics and engineering, clarity beats cleverness. CASE statements are more transparent, especially for teams and long-term projects.

Why This Matters in Real Projects

Every dataset hides patterns. Quarter-wise analysis uncovers seasonality, business cycles, performance jumps, and resource planning needs. In many organisations, leaders expect analysts to translate raw numbers into actionable stories. Quarter logic becomes a building block for those stories.

When people understand your SQL, they trust your analysis. And when they trust your analysis, they start approaching you for deeper guidance, collaborations, and responsibilities. This is how skillful work quietly builds reputation, one query at a time.

Dates may look dull, but they often decide the direction of a project, a report, or sometimes even a career. In Oracle SQL, mastering small techniques like these creates a strong foundation for bigger analytical work.







Comments