文件名称:数据库多表查询及嵌套查询子查询语句示例
文件大小:1KB
文件格式:
更新时间:2014-10-19 09:57:21
数据库 查询语句 多表查询 嵌套查询子
简单数据库但表查询 select * from kjbdsjk where 姓名 = 王勇 and 分数 = 87 group by 课程 order by 分数 1.利用FROM子句进行多表查询:select kjbdsjk.编号,kjbdsjk.姓名,kjbdsjk.职业,duobiao.收入 from kjbdsjk,duobiao where kjbdsjk.编号 = duobiao.编号 and duobiao.收入 >3000 2.合并多个结果集:select 编号,姓名,年龄 from kjbdsjk union select 编号,姓名,年龄 from shuzcx 说明UNION运算符合并多个结果集. 3.简单嵌套查询:select * from kjbdsjk where 姓名 in (select 姓名 from duobiao where 奖金 >= 1000) 4.复杂嵌套查询:select * from duobiao where year(日期)=2006 and monnth(日期)=5 and 姓名 in (select 负责人 from bumenbiao where 负责人 in (select 姓名 from kjbdsjk where 年龄>20)) order by 编号 5.用子查询作派生的表:select 年龄,count(*) as 相同年龄 from (select top 10 年龄 from kjbdsjk order by 编号) as t group by 年龄 6.把子查询作为表达式:select t.职业,t.平均年龄 from (select 职业,avg(年龄) as 平均年龄 from kjbdsjk group by 职业) as t where 平均年龄 >20 7.在UPDATE语句中应用子查询:update kjbdsjk set 工资 = 工资+1000 where 工资 in (select 工资 from kjbdsjk where 工资 > "+stredit+")