i want to display the employee names which having names start with a and b ,it should be like list will display employees with 'a' as a first letter and then the 'b' as a first letter...
我想显示名字以a和b开头的员工姓名,它应该像list一样显示员工'a'作为第一个字母,然后'b'作为第一个字母......
so any body tell me what is the command to display these...
所以任何身体告诉我显示这些的命令是什么......
10 个解决方案
#1
24
To get employee names starting with A or B listed in order...
要按顺序列出以A或B开头的员工姓名......
select employee_name
from employees
where employee_name LIKE 'A%' OR employee_name LIKE 'B%'
order by employee_name
If you are using Microsoft SQL Server you could use
如果您使用的是Microsoft SQL Server,则可以使用
....
where employee_name LIKE '[A-B]%'
order by employee_name
This is not standard SQL though it just gets translated to the following which is.
这不是标准的SQL,虽然它只是被翻译成以下的。
WHERE employee_name >= 'A'
AND employee_name < 'C'
For all variants you would need to consider whether you want to include accented variants such as Á
and test whether the queries above do what you want with these on your RDBMS and collation options.
对于所有变体,您需要考虑是否要包含重音变体(例如Á)并测试上面的查询是否在您的RDBMS和排序规则选项上执行了这些操作。
#2
4
select columns
from table
where (
column like 'a%'
or column like 'b%' )
order by column asc
#3
2
Regular expressions work well if needing to find a range of starting characters. The following finds all employee names starting with A, B, C or D and adds the “UPPER” call in case a name is in the database with a starting lowercase letter. My query works in Oracle (I did not test other DB's). The following would return for example:
Adams
adams
Dean
dean
如果需要查找一系列起始字符,正则表达式可以很好地工作。以下查找以A,B,C或D开头的所有员工姓名,并添加“UPPER”调用,以防名称在数据库中以起始小写字母显示。我的查询适用于Oracle(我没有测试其他数据库)。以下将返回例如:Adams adams Dean dean
This query also ignores case in the ORDER BY via the "lower" call:
此查询还通过“较低”调用忽略ORDER BY中的大小写:
SELECT employee_name
FROM employees
WHERE REGEXP_LIKE(UPPER(TRIM(employee_name)), '^[A-D]')
ORDER BY lower(employee_name)
#4
0
What cfengineers said, except it sounds like you will want to sort it as well.
cfengineers说了什么,除了听起来你也想要对它进行排序。
select columns
from table
where (
column like 'a%'
or column like 'b%' )
order by column
Perhaps it would be a good idea for you to check out some tutorials on SQL, it's pretty interesting.
也许你最好查看一些关于SQL的教程,这很有意思。
#5
0
If you're asking about alphabetical order the syntax is:
如果您询问字母顺序,则语法为:
SELECT * FROM table ORDER BY column
the best example I can give without knowing your table and field names:
在不知道您的表和字段名称的情况下,我可以提供的最佳示例:
SELECT * FROM employees ORDER BY name
#6
0
select name_last, name_first
from employees
where name_last like 'A%' or name_last like 'B%'
order by name_last, name_first asc
#7
0
select *
from stores
where name like 'a%' or
name like 'b%'
order by name
#8
0
select employee_name
from employees
where employee_name LIKE 'A%' OR employee_name LIKE 'B%'
order by employee_name
#9
0
Here what I understood from the question is starting with "a " and then "b" ex:
在这里我从问题中理解的是从“a”开始,然后是“b”ex:
- abhay
- abhishek
- abhinav
So there should be two conditions and both should be true means you cant use "OR" operator Ordered by is not not compulsory but its good if you use.
所以应该有两个条件,两个都应该是真的意味着你不能使用“OR”运算符顺序不是强制性的,但如果你使用它的好处。
Select e_name from emp
where e_name like 'a%' AND e_name like '_b%'
Ordered by e_name
#10
0
From A to Z:
从A到Z:
select employee_name from employees ORDER BY employee_name ;
From Z to A:
从Z到A:
select employee_name from employees ORDER BY employee_name desc ;
#1
24
To get employee names starting with A or B listed in order...
要按顺序列出以A或B开头的员工姓名......
select employee_name
from employees
where employee_name LIKE 'A%' OR employee_name LIKE 'B%'
order by employee_name
If you are using Microsoft SQL Server you could use
如果您使用的是Microsoft SQL Server,则可以使用
....
where employee_name LIKE '[A-B]%'
order by employee_name
This is not standard SQL though it just gets translated to the following which is.
这不是标准的SQL,虽然它只是被翻译成以下的。
WHERE employee_name >= 'A'
AND employee_name < 'C'
For all variants you would need to consider whether you want to include accented variants such as Á
and test whether the queries above do what you want with these on your RDBMS and collation options.
对于所有变体,您需要考虑是否要包含重音变体(例如Á)并测试上面的查询是否在您的RDBMS和排序规则选项上执行了这些操作。
#2
4
select columns
from table
where (
column like 'a%'
or column like 'b%' )
order by column asc
#3
2
Regular expressions work well if needing to find a range of starting characters. The following finds all employee names starting with A, B, C or D and adds the “UPPER” call in case a name is in the database with a starting lowercase letter. My query works in Oracle (I did not test other DB's). The following would return for example:
Adams
adams
Dean
dean
如果需要查找一系列起始字符,正则表达式可以很好地工作。以下查找以A,B,C或D开头的所有员工姓名,并添加“UPPER”调用,以防名称在数据库中以起始小写字母显示。我的查询适用于Oracle(我没有测试其他数据库)。以下将返回例如:Adams adams Dean dean
This query also ignores case in the ORDER BY via the "lower" call:
此查询还通过“较低”调用忽略ORDER BY中的大小写:
SELECT employee_name
FROM employees
WHERE REGEXP_LIKE(UPPER(TRIM(employee_name)), '^[A-D]')
ORDER BY lower(employee_name)
#4
0
What cfengineers said, except it sounds like you will want to sort it as well.
cfengineers说了什么,除了听起来你也想要对它进行排序。
select columns
from table
where (
column like 'a%'
or column like 'b%' )
order by column
Perhaps it would be a good idea for you to check out some tutorials on SQL, it's pretty interesting.
也许你最好查看一些关于SQL的教程,这很有意思。
#5
0
If you're asking about alphabetical order the syntax is:
如果您询问字母顺序,则语法为:
SELECT * FROM table ORDER BY column
the best example I can give without knowing your table and field names:
在不知道您的表和字段名称的情况下,我可以提供的最佳示例:
SELECT * FROM employees ORDER BY name
#6
0
select name_last, name_first
from employees
where name_last like 'A%' or name_last like 'B%'
order by name_last, name_first asc
#7
0
select *
from stores
where name like 'a%' or
name like 'b%'
order by name
#8
0
select employee_name
from employees
where employee_name LIKE 'A%' OR employee_name LIKE 'B%'
order by employee_name
#9
0
Here what I understood from the question is starting with "a " and then "b" ex:
在这里我从问题中理解的是从“a”开始,然后是“b”ex:
- abhay
- abhishek
- abhinav
So there should be two conditions and both should be true means you cant use "OR" operator Ordered by is not not compulsory but its good if you use.
所以应该有两个条件,两个都应该是真的意味着你不能使用“OR”运算符顺序不是强制性的,但如果你使用它的好处。
Select e_name from emp
where e_name like 'a%' AND e_name like '_b%'
Ordered by e_name
#10
0
From A to Z:
从A到Z:
select employee_name from employees ORDER BY employee_name ;
From Z to A:
从Z到A:
select employee_name from employees ORDER BY employee_name desc ;