数据库笔记—2—基本查询
worker为已制作好的员工职工表 salary为已制作好的员工工作表
1.
select *
from worker
2.
select wname,wsex
from worker
3.
select wid as '排序',wname as '姓名'
from worker
4.
select wid,actualsalary
from salary
where actualsalary>=3000 --条件查询
5.
select wid,actualsalary
from salary
where actualsalary between 2000 and 3000 --between and 代表xx之间
6.
select wid,wname,wsex,depid
from worker
where depid in ('1','2') --in后面为只要有1个匹配
7.
select wname,wsex
from worker
where wname not like '_华%'
--4.含字符匹配谓词的查询(显示名字第二个有华字的职工姓名,性别)
select wname,wsex
from worker
where wname like '_华%'
8.
select *
from depart
where dmaster is null
9.
select wname,wsex,wparty
from worker
where wsex='男' and wparty='是'
--6.含多重条件运算符的查询(显示性别为男或者为党员的职工)
select wname,wsex,wparty
from worker
where wsex='男' or wparty='是'
10.
select AVG(totalsalary) as '2011-01-04的平均工资'
from salary
where sdate='2011-01-04';
11.
select COUNT(wid) as 职工的总数
from worker
--2查询职工的总数
select COUNT(*) as 职工的总数
from worker
12.
select COUNT(distinct wid) as 职工的总数 --distinct为后面的参数重复的值只计数一次
from salary
13.
select MIN(actualsalary) as 最低工资
from salary
14.
select Max(actualsalary) as 最高工资
from salary
15.
select SUM(actualsalary) as 工资总额
from salary
where sdate='2011-01-04';
16.
select top 2 *
from worker
17.
select distinct depid as 部门号
from worker
where wsex='女'
转载请注明原文地址: https://ju.6miu.com/read-964806.html