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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:17:10+00:00 2026-06-18T20:17:10+00:00

I just need a little help about SQL queries Here’s the situation ID FIRST_NAME

  • 0

I just need a little help about SQL queries

Here’s the situation

ID   FIRST_NAME LAST_NAME  START_DAT END_DATE  SALARY     CITY       DESCRIPTION
---- ---------- ---------- --------- --------- ---------- ---------- ---------------
01   Jason      Martin     25-JUL-96 25-JUL-06 1234.56    Toronto    Programmer
02   Alison     Mathews    21-MAR-76 21-FEB-86 6661.78    Vancouver  Tester
03   James      Smith      12-DEC-78 15-MAR-90 6544.78    Vancouver  Tester
04   Celia      Rice       24-OCT-82 21-APR-99 2344.78    Vancouver  Manager
05   Robert     Black      15-JAN-84 08-AUG-98 2334.78    Vancouver  Tester
06   Linda      Green      30-JUL-87 04-JAN-96 4322.78    New York   Tester
07   David      Larry      31-DEC-90 12-FEB-98 7897.78    New York   Manager
08   James      Cat        17-SEP-96 15-APR-02 1232.78    Vancouver  Tester

8 rows selected.

SQL> -- GROUP BY clause and AVG() function

SQL> SELECT city, AVG(salary)
2 FROM employee
3 GROUP BY city;


CITY AVG(SALARY)
---------- -----------
New York 6110.28

Toronto 1234.56

Vancouver 3823.78

The problem is I can’t find a way to extract those names having higher salaries from each avg(salary) for city

Example:

Vancouver has avg(salary) of 3823.78 so I should get the name of 2 people: alison and james because they have higher salary than the avg(salary) of new york

For now I only go to this query but not working

select FIRST_NAME,SALARY,CITY 
from employee 
where SALARY > (  select avg(SALARY) 
                  from employee 
                  group by CITY
                );

it tells me that subquery return more than 1 value

Hope someone can help me

  • 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-06-18T20:17:11+00:00Added an answer on June 18, 2026 at 8:17 pm

    Your query is returning more than one value. To restrict it to one value, you need a condition on city:

    select FIRST_NAME,SALARY,CITY
    from employee e
    where SALARY > (select avg(SALARY) 
                    from employee e2 
                    where e2.city = e.city 
                    group by CITY);
    

    This is called a correlated subquery. You can also write it as a join, which is the syntax that I would use. The group by CITY is, strictly speaking, unnecessary, but I think it makes the intention of the subquery clearer.

    You can rewrite this as a join by doing:

    select e.FIRST_NAME, e.SALARY, e.CITY
    from employee e join
         (select city, avg(salary) as avgSalary
          from employee
          group by city
         ) ec
         on e.city = ec.city
    where e.salary > ec.avgSalary
    

    Or, what would be my favorite way . . .

    select e.FIRST_NAME, e.SALARY, e.CITY
    from (select e.*,
                 avg(salary) over (partition by city) as avgSalary
          employee e
         ) e
    where e.salary > e.avgSalary
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just need a little help locating an error(?) in my code, is set the
I need a little help with my code here. So far, when I go
I need a little bit of help here. First off, I am not sure
Just need a little bit of Javascript to warn people that press the back
I've just started a project and need a little push in the right direction.
I've just started with releasing in core graphics, so I might need a little
Just need some quick clarification I have 2 Queries in my Access Database that
I just need a help in configuring hiberclipse for my eclipse indigo version. Install
I need help in understanding git rebase for this situation. I checked out a
Trying to implement Piwik using REST API over http but need a little help.

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.