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 6173709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:37:26+00:00 2026-05-23T23:37:26+00:00

I’m working with oracle and it’s group by clause seems to behave very differently

  • 0

I’m working with oracle and it’s group by clause seems to behave very differently than I’d expect.

When using this query:

SELECT stats.gds_id,
  stats.stat_date,
  SUM(stats.A_BOOKINGS_NBR) as "Bookings",
  SUM(stats.RESPONSES_LESS_1_NBR) as "<1",
  SUM(stats.RESPONSES_LESS_2_NBR) AS "<2",
  SUM(STATS.RESPONSES_LESS_3_NBR) AS "<3",
  SUM(stats.RESPONSES_LESS_4_NBR) AS "<4",
  SUM(stats.RESPONSES_LESS_5_NBR) AS "<5",
  SUM(stats.RESPONSES_LESS_6_NBR + stats.RESPONSES_LESS_7_NBR + stats.RESPONSES_GREATER_7_NBR) AS ">5",
  SUM(stats.RESPONSES_LESS_6_NBR) AS "<6",
  SUM(stats.RESPONSES_LESS_7_NBR) AS "<7",
  SUM(stats.RESPONSES_GREATER_7_NBR) AS ">7",
  SUM(stats.RESPONSES_LESS_1_NBR + stats.RESPONSES_LESS_2_NBR + stats.RESPONSES_LESS_3_NBR + stats.RESPONSES_LESS_4_NBR + stats.RESPONSES_LESS_5_NBR + stats.RESPONSES_LESS_6_NBR + stats.RESPONSES_LESS_7_NBR + stats.RESPONSES_GREATER_7_NBR) as "Total"
FROM gwydb.statistics stats
WHERE stats.stat_date >= '01-JUN-2011'
GROUP BY stats.gds_id, stats.stat_date

I get results like this:

GDS_ID  STAT_DATE   Bookings    <1      <2  <3  <4  <5  >5  <6  <7  >7  Total    
02      12-JUN-11   0           1       0   0   0   0   0   0   0   0   1
1A      01-JUN-11   15          831     52  6   2   2   4   1   1   2   897
1A      01-JUN-11   15          758     59  8   1   1   5   2   1   2   832
1A      01-JUN-11   10          593     40  2   2   1   2   1   0   1   640
1A      01-JUN-11   12          678     40  10  5   2   3   1   0   2   738
1A      01-JUN-11   24          612     56  6   1   3   4   0   0   4   682
1A      01-JUN-11   23          552     37  7   1   1   2   0   1   1   600
1A      01-JUN-11   35          1147    132 13  6   0   8   0   2   6   1306
1A      01-JUN-11   91          2331    114 14  5   1   14  3   1   10  2479

As you can see, I have multiple duplicate STAT_DATE’s per GDS_ID. Why is that, and how can I make it group by both of those? I.E. Sum the values for each GDS_ID per STAT_DATE.

  • 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-05-23T23:37:26+00:00Added an answer on May 23, 2026 at 11:37 pm

    Probably because STAT_DATE has a time component, which is being taken into account in the GROUP BY but not being displayed in the results due to the default format mask. To ignore the time, do this:

    SELECT stats.gds_id,
      TRUNC(stats.stat_date) stat_date,
      SUM(stats.A_BOOKINGS_NBR) as "Bookings",
      SUM(stats.RESPONSES_LESS_1_NBR) as "<1",
      SUM(stats.RESPONSES_LESS_2_NBR) AS "<2",
      SUM(STATS.RESPONSES_LESS_3_NBR) AS "<3",
      SUM(stats.RESPONSES_LESS_4_NBR) AS "<4",
      SUM(stats.RESPONSES_LESS_5_NBR) AS "<5",
      SUM(stats.RESPONSES_LESS_6_NBR + stats.RESPONSES_LESS_7_NBR + stats.RESPONSES_GREATER_7_NBR) AS ">5",
      SUM(stats.RESPONSES_LESS_6_NBR) AS "<6",
      SUM(stats.RESPONSES_LESS_7_NBR) AS "<7",
      SUM(stats.RESPONSES_GREATER_7_NBR) AS ">7",
      SUM(stats.RESPONSES_LESS_1_NBR + stats.RESPONSES_LESS_2_NBR + stats.RESPONSES_LESS_3_NBR + stats.RESPONSES_LESS_4_NBR + stats.RESPONSES_LESS_5_NBR + stats.RESPONSES_LESS_6_NBR + stats.RESPONSES_LESS_7_NBR + stats.RESPONSES_GREATER_7_NBR) as "Total"
    FROM gwydb.statistics stats
    WHERE stats.stat_date >= '01-JUN-2011'
    GROUP BY stats.gds_id, TRUNC(stats.stat_date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build

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.