[英]Query with more than one condition
I want to display the salary from my employees
table where the salary has to be between 6100 and 6400, and first_name
is like a%. 我想显示employees
表中的薪水,薪水必须在6100到6400之间, first_name
就像%。
I wrote this query : 我写了这个查询:
select salary from employees where salary in (6100,6400) and first_name like 'a%';
But it shows no rows selected. 但它显示没有选择任何行。 How should I change the query to find rows that match both conditions? 我应该如何更改查询以查找符合这两个条件的行?
Use BETWEEN
instead of IN
: 使用BETWEEN
而不是IN
:
SELECT salary
FROM employees
WHERE salary BETWEEN 6100 AND 6400
AND first_name LIKE 'a%';
Use BETWEEN this way 以这种方式使用BETWEEN
select salary
from employees
where salary BETWEEN 6100 AND 6400
and first_name like 'a%';
Because you're using the IN
statement rather than the BETWEEN
statement, the data returned by your current query would only contain employee's with salaries equal to 6100 or 6400 and a first name starting with the lower case letter 'a'. 因为您使用的是IN
语句而不是BETWEEN
语句,所以当前查询返回的数据只包含薪水等于6100或6400的员工以及以小写字母“a”开头的名字。
Please try the following: 请尝试以下方法:
SELECT SALARY
FROM EMPLOYEES
WHERE SALARY BETWEEN 6100 AND 6400
AND FIRST_NAME LIKE 'a%';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.