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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:54:13+00:00 2026-05-26T05:54:13+00:00

I am currently having an issue with the GROUP BY statements in Oracle Database

  • 0

I am currently having an issue with the GROUP BY statements in Oracle Database 10g with my database.

I have four tables in this database – Advertisements, Staff, StaffGrade and StaffOnAd. What I’m trying to query is for advertisements with more than three staff members working on them, I want to list that advert title and the number of staff members who have a payment grade greater than 2.

Below is my attempt:

SELECT Camp.Title 
FROM Campaign Camp
LEFT JOIN WorksOn Wo ON Camp.Title = Wo.Title
LEFT JOIN Staff Stf ON Wo.StaffNo = Stf.StaffNo
LEFT JOIN StaffOnGrade StfOGrde ON Stf.StaffNo = StfOGrde.StaffNo
WHERE StfOGrde.Grade > 2 AND Camp.Title IN (SELECT Camp2.Title FROM Campaign Camp2
LEFT JOIN WorksOn Wo2 ON Camp2.Title = Wo2.Title
WHERE COUNT(Camp2.Title) > 3)
GROUP BY Camp.Title

The error I received with the above is: ORA-00934: group function is not allowed here

I searched around and basically that error tells me that the way I’m grouping is wrong but I have no idea why that is. Also I was just wondering was is the correct way to format the above code?

Any help is appreciated.

NOTE: Just some more information regarding the tables below

  • Advertisements basically has fields regarding air date etc.
  • Staff has their personal details recorded.
  • StaffGrade shows what payment grade a staff member is on.
  • StaffOnAd shows what staff member works on what advertisement by the
    title of the ad.

EDIT 1: Tried the following after comments:

SELECT Camp.Title 
FROM Campaign Camp
LEFT JOIN WorksOn Wo ON Camp.Title = Wo.Title
LEFT JOIN Staff Stf ON Wo.StaffNo = Stf.StaffNo
LEFT JOIN StaffOnGrade StfOGrde ON Stf.StaffNo = StfOGrde.StaffNo
WHERE StfOGrde.Grade > 2 AND Camp.Title IN (SELECT Camp2.Title FROM Campaign Camp2
LEFT JOIN WorksOn Wo2 ON Camp2.Title = Wo2.Title
HAVING COUNT(Camp2.Title) > 3)
GROUP BY Camp.Title

However, I received a new error: ORA-00937: not a single-group group function

EDIT 2:

SELECT Camp.Title 
FROM Campaign Camp
  LEFT JOIN WorksOn Wo ON Camp.Title = Wo.Title
  LEFT JOIN Staff Stf ON Wo.StaffNo = Stf.StaffNo
  LEFT JOIN StaffOnGrade StfOGrde ON Stf.StaffNo = StfOGrde.StaffNo
WHERE StfOGrde.Grade > 2 
  AND Camp.Title IN 
      ( SELECT Camp2.Title 
        FROM Campaign Camp2
          LEFT JOIN WorksOn Wo2 
            ON Camp2.Title = Wo2.Title
        GROUP BY Camp2.Title
        HAVING COUNT(Camp2.Title) > 3
      )
GROUP BY Camp.Title

No errors in this revised query. However, the only results that are being displayed is titles of the advertisement where I also need the amount of staff members working on that advert with grade payment greater than 2. I just assumed that the last group by statement would fix this issue, but I don’t think its necessary.

  • 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-26T05:54:13+00:00Added an answer on May 26, 2026 at 5:54 am

    First of all… Always, when you put into your select some condition in the left joined table, you’ll have an inner join.
    Based in your requirements:

    • List with advert title and number of staff members who have a payment grade grater than 2
    • Advertisements with more than 3 Staff members

    I would do something like this:

        SELECT title, SumGradeGreaterThan2
          FROM (SELECT   camp.title, COUNT (*) AS StaffMembers,
                         SUM (CASE
                                 WHEN stfogrde.grade > 2
                                    THEN 1
                                 ELSE 0
                              END) AS SumGradeGreaterThan2
                    FROM  Campaign Camp
                    LEFT JOIN WorksOn Wo ON Camp.Title = Wo.Title
                    LEFT JOIN Staff Stf ON Wo.StaffNo = Stf.StaffNo
                    LEFT JOIN StaffOnGrade StfOGrde ON Stf.StaffNo = StfOGrde.StaffNo
                GROUP BY camp.title)
         WHERE StaffMembers > 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue with multiple markers on google maps - I currently have
I'm currently using this jQuery validate plugin and having an issue in IE where
I'm currently having an issue where I have a javascript object that is trying
I am currently having an issue with radio buttons and grouping. I have an
I am currently having an issue with BackgroundWorker running on Windows Server 2003. I
I'm currently having an issue wrapping my brain around the notion of converting my
Hi All I am currently having an issue calling a WCF service from a
I'm currently having a major issue with a python script. The script runs arbitrary
Hopefully someone can shed a little light on an issue that I'm currently having
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS

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.