资源描述:
《计算机二级VF命令语言.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、简单查询SELECT……FROM……WHERE……1、查询表中指定的字段select工资from职工去掉重复的-----distinctselectdistinct工资from职工select职工号,工资from职工2、查询表中所有字段select*from职工3、有条件的查询selectdistinct仓库号from职工where工资>1210select职工号from职工where工资>1230select职工号from职工where工资<1250and(仓库号="WH1"OR仓库号="WH2")select*from职
2、工where工资>=1220AND工资<=1240between……ANDselect*from职工where工资between1220AND1240like(%和_)select*from供应商where供应商名like"%公司"select*from供应商where供应商名like"%厂"notselect*from供应商where地址!="北京"select*from供应商where地址<>"北京"select*from供应商wherenot(地址="北京")select*from职工where工资notbetween
3、1220AND1240select*from供应商where供应商名notlike"%厂"简单连接查询多个关系中含有相同属性名时,必须用关系前缀指明属性所属的关系。否则可不加前缀。关系名.属性名或关系名->属性名select职工号,城市from职工,仓库;where职工.仓库号=仓库.仓库号select职工号,城市from职工,仓库;where职工.仓库号=仓库.仓库号and工资>1230select职工号,城市from职工,仓库;where职工->仓库号=仓库->仓库号and工资>1230select职工号,城市from职
4、工,仓库;where职工->仓库号=仓库->仓库号and面积>400别名.属性名或别名->属性名select职工号,城市from职工a,仓库b;wherea.仓库号=b.仓库号and面积>400嵌套查询检索关系X中的元组时,它的条件依赖于相关的Y中元组的属性值。1、返回单值查找和职工E4挣同样工资的所有职工(1250)select职工号from职工where工资=;(select工资from职工where职工号="E4")2、返回一组值SELECT城市FROM仓库WHERE仓库号IN;(SELECT仓库号FROM职工WHER
5、E工资=1250)SELECT城市FROM仓库WHERE仓库号IN("WH1","WH2")SELECT*FROM仓库WHERE仓库号NOTIN;(SELECT仓库号FROM职工WHERE工资<=1210)SELECT*FROM仓库WHERE仓库号IN(SELECT仓库号FROM职工)(WH1,WH2,WH3)SELECT*FROM仓库WHERE仓库号IN(SELECT仓库号FROM职工);AND仓库号NOTIN;(SELECT仓库号FROM职工WHERE工资<=1210)或:SELECT*FROM仓库WHERE仓库号NOT
6、IN;(SELECT仓库号FROM职工WHERE工资<=1210);AND仓库号IN(SELECT仓库号FROM职工)排序ORDERBY(ASCDESC)select*from职工ORDERBY工资select*from职工ORDERBY工资descselect*from职工ORDERBY仓库号,工资desc简单计算selecount(*)from供应商selecount(地址)from供应商(有重复4)selecount(dist地址)from供应商(3)selesum(工资),avg(工资),max(工资),min(工资
7、)from职工selesum(工资)as工资总和,avg(工资)as工资平均值,max(工资)as工资最大值,min(工资)as工资最小值from职工selemax(工资),min(工资)from职工where仓库号="WH2"selesum(工资)from职工where仓库号in;(sele仓库号from仓库where城市="北京"or城市="上海")分组SELECT仓库号,AVG(工资)FROM职工GROUPBY仓库号SELECT仓库号,COUNT(*),AVG(工资)FROM职工;GROUPBY仓库号HAVINGCOU
8、NT(*)>=2空值SELECT*FROM订购单WHERE供应商号isnullSELECT*FROM订购单WHERE供应商号isNOTnull别名与自然连接select职工号,城市from职工a,仓库b;wherea.仓库号=b.仓库号SELECT供应商名FROM供应商a,订购单b,职工c