📜  SQL查询以从表中查找唯一的列值

📅  最后修改于: 2021-08-24 16:45:40             🧑  作者: Mango

我们使用一个名为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

SQL查询以查找“管理员”部门中的行数。

SELECT COUNT(*) 
FROM Geeks 
WHERE DEPARTMENT = 'Admin';

输出 –

(No column name)
3