简体   繁体   中英

Incorrect syntax near AND in SQL

I need to fix the following query but I cannot see the mistake. Could you please point me what is wrong?

select *
from(
     SELECT a.fisrt_name,a.last_name,a.job_id
     FROM employees A
     WHERE A.salary >(Select avg(salary) from employees)) and a.salary < select (max(salary) from employees)
) b
where b.job_id=SY_ANA;

where clause condition string should be quoted

 select *
    from(
         SELECT a.fisrt_name,a.last_name,a.job_id
         FROM employees a
         WHERE a.salary >(Select avg(salary) from employees)
             and a.salary < (select max(salary) from employees)
    ) b
    where b.job_id='SY_ANA';

And i removed extra parenthesis

You need to delete this little fella ) right after employees

select *
from(
     SELECT a.fisrt_name,a.last_name,a.job_id
     FROM employees A
     WHERE A.salary >(Select avg(salary) from employees) and a.salary < select (max(salary) from employees)
) b
where b.job_id=SY_ANA;
select b.*
from(
     SELECT a.fisrt_name,a.last_name,a.job_id
     FROM employees A
     WHERE A.salary >(Select avg(salary) from employees) and a.salary < (select max(salary) from employees)
) b
where b.job_id="SY_ANA";

You are missing brackets in inner query and quotes in where condition

    select *
from(
     SELECT a.fisrt_name,a.last_name,a.job_id
     FROM employees A
     WHERE A.salary >(Select avg(salary) from employees)) and a.salary < (select max(salary) from employees)
) b
where b.job_id='SY_ANA';

(select max(salary) from employees) was select (max(salary) from employees) also missing qoutes in where

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM