Close Menu
Şevket Ayaksız
    What's Hot

    Word Pagination: Keep a Heading with the Paragraph That Follows

    November 10, 2026

    Oracle Running Totals: Choose ROWS or RANGE Before Trusting the Result

    November 10, 2026

    Java String.split: Preserve Empty Fields When Their Position Matters

    November 10, 2026
    • software
    • Gadgets
    Şevket AyaksızŞevket Ayaksız
    • Home
    • Technology

      Apple: iPhone 17 and Older Models Hit With Unexpected $100 Price Increase

      September 10, 2026

      Apple Watch Intelligence Could Be a Major Accessibility Breakthrough

      September 10, 2026

      Apple May Skip the Base iPhone 18 This Year

      September 10, 2026

      FCC changes robot vacuum rules, potentially affecting future models

      August 8, 2026

      Samsung’s new 2TB 990 SSD drops to its lowest price yet

      August 6, 2026
    • Adobe

      Illustrator Scaling: Keep Strokes and Effects in Proportion

      November 10, 2026

      Illustrator Global Swatches: Make Color Changes Follow Your Design

      November 8, 2026

      Adobe Acrobat Bookmarks: Give Long PDFs a Useful Navigation Structure

      November 7, 2026

      How to Keep a Photoshop Adjustment on the Right Layer

      November 6, 2026

      Illustrator Linked Images: Build a Handoff That Opens Correctly on Another Computer

      November 3, 2026
    • Microsoft

      Word Pagination: Keep a Heading with the Paragraph That Follows

      November 10, 2026

      PowerPoint Selection Pane: Find and Manage Objects Behind Other Objects

      November 10, 2026

      Excel Data Validation: Guide Entry and Check What Arrives Later

      November 8, 2026

      PowerPoint Speaker Notes: Prepare the Message Behind the Slides

      November 7, 2026

      Excel Cell References: Lock Only What Your Formula Needs

      November 6, 2026
    • java

      Java String.split: Preserve Empty Fields When Their Position Matters

      November 10, 2026

      Java String Case Conversion: Choose the Locale Explicitly

      November 8, 2026

      Java Optional: Choose Between a Default Value and Deferred Work

      November 7, 2026

      Java BigDecimal Equality: Decide Whether Scale Matters

      November 7, 2026

      Java Paths: When to Normalize, Make Absolute, or Resolve the Real File

      November 6, 2026
    • Oracle

      Oracle Running Totals: Choose ROWS or RANGE Before Trusting the Result

      November 10, 2026

      Oracle NULLIF: Handle a Zero Denominator Without Inventing a Result

      November 8, 2026

      Oracle WHERE and HAVING: Filter the Right Level of Your Report

      November 8, 2026

      Oracle ROW_NUMBER: Make “Latest Record” Queries Deterministic

      November 7, 2026

      Oracle CASE Expressions: Put Overlapping Rules in the Right Order

      November 6, 2026
    Şevket Ayaksız
    Anasayfa » Oracle WHERE and HAVING: Filter the Right Level of Your Report
    Oracle

    Oracle WHERE and HAVING: Filter the Right Level of Your Report

    By sevketayaksizNovember 8, 2026No Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Oracle WHERE and HAVING: Filter the Right Level of Your Report
    Share
    Facebook Twitter LinkedIn Pinterest Email

    A sales report can return plausible totals while answering the wrong question. One common cause is filtering individual transactions when the requirement was to filter the combined result for each customer.

    Oracle SQL provides both WHERE and HAVING, but they operate at different levels of a grouped query. Understanding that difference starts with describing which rows should contribute and which completed groups should appear.

    Use WHERE to define the contributing rows

    A WHERE condition restricts the rows selected by a query. In a typical grouped report, this establishes the population from which the aggregates are calculated.

    Suppose a report should consider only completed orders. The row-level condition belongs in WHERE, because an order’s status determines whether it contributes to the report at all.

    This is a question about individual records: should this particular order be included?

    Oracle’s SELECT documentation distinguishes this filtering from the restrictions applied to grouped results.

    Use HAVING to select completed groups

    Aggregate functions summarize groups of rows. HAVING can then restrict the output according to those aggregate results. Oracle explicitly documents its use for eliminating groups based on aggregate values rather than individual row values.

    For an illustrative orders table, the query might be:

    SELECT customer_id,
           SUM(order_total) AS completed_total
    FROM orders
    WHERE status = 'COMPLETE'
    GROUP BY customer_id
    HAVING SUM(order_total) >= 1000;

    This asks for customers whose completed orders total at least 1,000. It does not require every contributing order to be worth 1,000.

    The distinction becomes clear with a small example. A customer with two completed orders of 600 contributes a total of 1,200 and qualifies. A customer with a single completed order of 900 does not.

    Watch for a valid query that changes the question

    Now consider placing order_total >= 1000 in the WHERE clause. That removes the two 600 orders before the customer total is calculated.

    The resulting query may run without an error. Its meaning has changed to something closer to “summarize qualifying large orders,” rather than “find customers with qualifying combined spending.”

    This is why SQL review should include representative data, not only syntax checks. A query can be technically valid while implementing the wrong business rule.

    Write the requirement in two sentences before editing SQL: “Include these records in the calculation” and “Show groups meeting this condition.” The sentences often reveal where each predicate belongs.

    Check boundary cases explicitly

    Build a small review dataset with one customer just below the threshold, one exactly on it, and one above it. Include a customer whose qualifying total is made from several smaller orders.

    Also include an excluded status with a large amount. That row should not affect a report defined around completed orders.

    If refunds, cancellations, or missing amounts are possible, establish how they should affect the calculation before finalizing the query. Their business treatment cannot be inferred from the presence of SUM.

    Finally, describe the result precisely in the report heading. “Customers with completed-order totals of at least 1,000” communicates more than “High-value customers.”

    Correct placement of WHERE and HAVING keeps the selected population and the displayed summary aligned with the question the report is supposed to answer.

    Sources

    • Oracle: SELECT statement reference
    • Oracle: Aggregate functions
    Views: 18
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    sevketayaksiz
    • Website

    Related Posts

    Oracle Running Totals: Choose ROWS or RANGE Before Trusting the Result

    November 10, 2026

    Oracle NULLIF: Handle a Zero Denominator Without Inventing a Result

    November 8, 2026

    Oracle ROW_NUMBER: Make “Latest Record” Queries Deterministic

    November 7, 2026
    Add A Comment

    Comments are closed.

    Şevket Ayaksız
    Instagram
    • Home
    • Adobe
    • microsoft
    • java
    • Oracle
    • Contact
    © 2026 Theme Designed by Şevket Ayaksız.

    Type above and press Enter to search. Press Esc to cancel.