SQL中AND之间的语法不正确

时间:2018-10-15 10:31:36

标签: mysql sql

我需要修复以下查询,但看不到错误。你能指出我出什么问题了吗?

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;

4 个答案:

答案 0 :(得分:2)

where子句条件字符串应用引号

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

我删除了多余的括号

答案 1 :(得分:0)

您需要在<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="row"> <div class="col-6"> <div class="table-responsive dashboard-table-responsive"> <table class="table table-sm dashboard-table"> <thead> <tr> <th scope="col" class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input headerCheckbox" id="customControlInline2" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline2"></label> </div> </th> <th scope="col" class="p-l-0">Name</th> <th scope="col">Size</th> <th scope="col">Upload at</th> <th scope="col" class="text-right">Views</th> </tr> </thead> <tbody class="dashboard-table-tbody"> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input checkBox" id="customControlInline3" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline3"></label> </div> </th> <td class="p-l-0"><a href="https://www.nexshot.io">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr class="active"> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline4" type="checkbox" checked> <label class="custom-control-label table-checkbox-label" for="customControlInline4"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline5" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline5"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline6" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline6"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline7" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline7"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline8" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline8"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> </tbody> </table> </div> </div> <div class="col-6"> <div class="table-responsive dashboard-table-responsive"> <table class="table table-sm dashboard-table"> <thead> <tr> <th scope="col" class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input headerCheckbox" id="customControlInline321" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline321"></label> </div> </th> <th scope="col" class="p-l-0">Name</th> <th scope="col">Size</th> <th scope="col">Upload at</th> <th scope="col" class="text-right">Views</th> </tr> </thead> <tbody class="dashboard-table-tbody"> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input checkBox" id="customControlInline398" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline398"></label> </div> </th> <td class="p-l-0"><a href="https://www.nexshot.io">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr class="active"> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline544" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline544"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline536541065" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline536541065"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline636" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline636"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline987" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline987"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> <tr> <td class="table-checkbox-col-head"> <div class="custom-control custom-checkbox defaultCheckbox table-checkbox"> <input class="custom-control-input" id="customControlInline898" type="checkbox"> <label class="custom-control-label table-checkbox-label" for="customControlInline898"></label> </div> </th> <td class="p-l-0"><a href="#">File-Name.mp4</a></td> <td>137.3kB</td> <td>10/9/2018, 4:53:28 PM</td> <td class="text-right">10</td> </tr> </tbody> </table> </div> </div> </div>之后删除这个小家伙)

employees

答案 2 :(得分:0)

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";

您在内部查询中缺少括号,而在where条件中没有引号

答案 3 :(得分:0)

    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)select (max(salary) from employees) 在哪里也缺少qoutes