DMSQL简介 DM_SQL语言是一种介于关系代数与关系演算之间的语言,其功能主要包括数据定义、 查询、操纵和控制四个方面,通过各种不同的SQL语句来实现。按照所实现的功能,DM_SQL 语句分为以下几种:
在嵌入方式中,为了协调DM_SQL语言与主语言不同的数据处理方式,DM_SQL语言引 入了游标的概念。因此在嵌入方式下,除了数据查询语句(一次查询一条记录)外,还有几 种与游标有关的语句:
select() from (); 第一个括号可以接(*,列命名,||,alias,distinct,表达式)
过滤: select () from () where(); where后边可以接(比较运算,逻辑运算,NULL/NOT NULL,in,between…and,模糊查询like) 排序:select () from () where() order by (asc / desc);
聚合函数 sum avg max min count select聚合函数(),列名 from () group by (列名) having ();
语法:select () from () join () on (); 找出每个用工所在的部门? select e.employee_name,d.department_name from employee e join department d on e.department_id=d.department_id;(问题,有员工没有部门) 左外连接 select e.employee_name,d.department_name from employee e left join department d on e.department_id=d.department_id;(解决员工没有部门)
左外连接(left join)
右外连接(right join)
全外连接 (full join)分类:单行 多行
机制:子查询的结果是主查询的条件,子查询先于主查询运行
单行:返回结果唯一
select () from () where ()=(sql语句);
找出和马学铭在同一个部门的人?(同名,可以使用in)
select department_id,employee_name from employee where department_id= (select department_id from employee where employee_name=‘马学铭’);
多行子查询:返回结果为多个 any all in exists
any(min) <any(max)
all(max) <all(min)
找出比1004部门所有人工资都高的? select employee_name,department_id,salary from employee where salary >all (select salary from employee where department_id=1004);
in:先运行子查询,子查询运行完,在运行主查询。
exists:先运行子查询,如果存在满足查询条件的,就去运行主查询,主查询没有满足条件的,再运行子查询,直到没有满足条件的。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。