Skip to main content
deleted 4 characters in body; edited title
Source Link
marc_s
  • 759.6k
  • 185
  • 1.4k
  • 1.5k

sql subquries SQL subqueries multiple value

iI just need a little help about sqlSQL queries

heresHere'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

theThe problem is i cantI can't find a way to extract those names having higher salaries from each avg(salary)avg(salary) for city example

Example: vancouver

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

forFor now iI only go to this query but not working

hopeHope someone can help me

sql subquries multiple value

i just need a little help about sql queries

heres 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 cant 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 bcoz they have higher salary than the avg(salary) of new york

for now i only go to this query but not working

hope someone can help me

SQL subqueries multiple value

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

Hope someone can help me

improved formating
Link
user330315
user330315

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

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

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

select FIRST_NAME,SALARY,CITY 
from employee 
where SALARY > (  select avg(SALARY) 
                  from employee 
                  group by CITY
                );
added 102 characters in body
Source Link
user359040
user359040
Loading
added 142 characters in body
Source Link
Mahmoud Gamal
  • 80.2k
  • 18
  • 143
  • 168
Loading
Source Link
Loading