我需要来自表工作者的LAST_NAME,JOB_ID,SALARY列,并且作业ID需要为SH_CLERK或SA_REP,而SALARY列不能等于1000,2600,3000,7000,8000或9000
SELECT `LAST_NAME`, `JOB_ID`, `SALARY` FROM `workers`
WHERE `JOB_ID` = SH_CLERK OR SA_REP AND `SALARY` != 1000 and 2600 and 3000 and 7000 and 8000 and 9000;
我不知道什么是错的,我在'where子句'错误中得到#1054 - 未知列'SH_CLERK'。
谢谢!
答案 0 :(得分:1)
在字符串周围添加引号。
将多个OR
切换为使用IN
代替。
SELECT LAST_NAME, JOB_ID, SALARY
FROM workers
WHERE JOB_ID IN ('SH_CLERK', 'SA_REP')
AND SALARY NOT IN (1000, 2600, 3000, 7000, 8000, 9000);
答案 1 :(得分:0)
SELECT LAST_NAME, JOB_ID, SALARY
FROM workers
WHERE JOB_ID IN ('SH_CLERK', 'SA_REP') AND
SALARY NOT IN (1000, 2600, 3000, 7000,8000, 9000)
答案 2 :(得分:0)
假设我是否正确理解了问题,
如果job_id
是数字数据而SH_CLERK或SA_REP是从其他表中获取的。
`Select last_name, job_id, salary
from workers
where job_id = (select id from <user table>
where <sh_clerk/sa_rep column name field> like 'SH_CLERK' or
<sh_clerk/sa_rep column name field> like 'SA_REP')
and SALARY not in(1000, 2600, 3000, 7000, 8000, 9000);`
<user table>
是SH_CLERK或SA_REP取自
<sh_clerk/sa_rep column name field>
是<user table>