注:蓝色字体说明是第二种做法。
一、基本查询
例1 从职工关系中检索所有工资值。
Select 工资 from 职工表
例2 检索仓库关系中的所有元组。
Select * from 仓库表
二、条件查询
例3 检索工资多于1230元的职工号。
Select 职工号 from 职工表 where 工资>1230
例4 检索哪些仓库有工资多于1210的职工。
Select distinct仓库号 from 职工表 where 工资>1210
例5 给出在仓库“WH1”或“WH2”工作,并且工资少于1250的职工号。
做法1:Select 职工号 from 职工表 ;
where 工资<1250 and (仓库号="WH1" or 仓库号="WH2")
做法2:Select 职工号 from 职工表 where 工资<1250 and 仓库号 in ("WH1","WH2")
例6 找出工资多于1230元的职工号和他们所在的城市。
select 职工号,城市 ;
from 职工表,仓库表;
where 职工表.仓库号=仓库表.仓库号 and 工资>1230
例7 检索出工资在1220元到12