我们采用一个名为 Geeks 的示例表,并通过对其应用各种 SQL 查询来返回唯一的列值。
表 –极客
G_ID | FIRSTNAME | LASTNAME | JOININGDATE | DEPARTMENT |
---|---|---|---|---|
1 | Mohan | Arora | 7-08-2019 | DBA |
2 | Nisha | Verma | 25-03-2017 | Admin |
3 | Vishal | Gupta | 9-01-2020 | DBA |
4 | Amita | Singh | 5-12-2017 | Writer |
5 | Vishal | Bharti | 3-05-2018 | Admin |
6 | Vinod | Diwan | 19-04-2018 | Review |
7 | Sheetal | Kumar | 5-01-2017 | Review |
8 | Geeta | Chauan | 5-02-2019 | Admin |
9 | Mona | Mishra | 15-01-2018 | Writer |
SQL 查询从 Geeks 表中查找列部门的唯一值。
Select distinct DEPARTMENT
from Geeks;
输出 –
DEPARTMENT |
---|
Admin |
DBA |
Review |
Writer |
SQL 查询以查找名称为“DBA”的列部门的详细信息。
Select *
from Geeks
where DEPARTMENT like 'DBA%';
输出 –
G_ID | FIRSTNAME | LASTNAME | JOININGDATE | DEPARTMENT |
---|---|---|---|---|
1 | Mohan | Arora | 7-08-2019 | DBA |
3 | Vishal | Gupta | 9-01-2020 | DBA |
用于查找部门“Admin”中行数的 SQL 查询。
SELECT COUNT(*)
FROM Geeks
WHERE DEPARTMENT = 'Admin';
输出 –
(No column name) |
---|
3 |