SQL |查询以使用不同选项从表中选择名称
让我们考虑一下名为“ Geeks ”的下表:
G_ID | FIRSTNAME | LASTNAME | DEPARTMENT |
---|---|---|---|
1 | Mohan | Arora | DBA |
2 | Nisha | Verma | Admin |
3 | Vishal | Gupta | DBA |
4 | Amita | Singh | Writer |
5 | Vishal | Diwan | Admin |
6 | Vinod | Diwan | Review |
7 | Sheetal | Kumar | Review |
8 | Geeta | Chauhan | Admin |
9 | Mona | Mishra | Writer |
使用别名作为 NAME 从 Geeks 表中写入“FIRSTNAME”的 SQL 查询。
Select FIRSTNAME AS NAME
from Geeks;
输出 -
NAME |
---|
Mohan |
Nisha |
Vishal |
Amita |
Vishal |
Vinod |
Sheetal |
Geeta |
Mona |
SQL 查询以大写形式从 Geeks 表中写入“FIRSTNAME”。
Select upper(FIRSTNAME)
from Geeks;
输出 -
(No column name) |
---|
MOHAN |
NISHA |
VISHAL |
AMITA |
VISHAL |
VINOD |
SHEETAL |
GEETA |
MONA |
SQL 查询从 Geeks 表中查找 FIRSTNAME 的前三个字符。
Select substring(FIRSTNAME, 1, 3)
from Geeks;
输出 -
(No column name) |
---|
Moh |
Nis |
Vis |
Ami |
Vis |
Vin |
She |
Gee |
Mon |
将 Geeks 表中的 FIRSTNAME 和 LASTNAME 写入单列 COMPLETENAME 的 SQL 查询应使用空格字符分隔它们。
Select CONCAT(FIRSTNAME, ' ', LASTNAME) AS 'COMPLETENAME'
from Geeks;
输出 -
COMPLETENAME |
---|
Mohan Arora |
Nisha Verma |
Vishal Gupta |
Amita Singh |
Vishal Diwan |
Vinod Diwan |
Sheetal Kumar |
Geeta Chauhan |
Mona Mishra |
编写一个 SQL 查询以按 FIRSTNAME Ascending 打印 Geeks 表 order 中的所有 Worker 详细信息。
Select *
from Geeks
order by FIRSTNAME asc;
输出 -
G_ID | FIRSTNAME | LASTNAME | DEPARTMENT |
---|---|---|---|
4 | Amita | Singh | Writer |
8 | Geeta | Chauan | Admin |
1 | Mohan | Arora | DBA |
9 | Mona | Mishra | Writer |
2 | Nisha | Verma | Admin |
7 | Sheetal | Kumar | Review |
6 | Vinod | Diwan | Review |
3 | Vishal | Gupta | DBA |
5 | Vishal | Diwan | Admin |