新增连接查询而不影响其他连接查询 请看图: 这种情况我们一般会使用左连接的方式. select e.ENAME,d.LOC,eb.RECEIVED from emp e join dept d on(e.DEPTNO=d.DEPTNO) left join emp_bonus eb on(eb.EMPNO=e.EMPNO) order by 2 上面这种可以实现的,但是不利于我们在写code语句中的复用. 下面是一种标量子查询我的方式,可以帮助我们复用部分sql. select e.ENAME,…
遍历字符串 我觉得首先要提出一个疑问: 一个数据库本身就是用于存储的,遍历字符串究竟有何意义? 先看如何实现的,毕竟sql service 是没有for循环,也没有loop和while的. select SUBSTRING(e.ENAME,t.ID,1) as sub from emp e,T10 t where e.ENAME='JONES' and t.ID<=len(e.ENAME) 的确是遍历了这个字符串JONES. 原理也十分的简单: select * from T10 T10 可以看…
select year(createdate) 年,month(createdate) 月,count(1) from public_cms_arcwhere (userid in (select id from cms_admin where userid='392') or userid='392')group by year(createdate),month(createdate)order by year(createdate) desc,month(createdate) desc…
查找只存在一个表中的数据 有两张表: EMP: select * from emp DEPT: 他们有共同的属性:deptno 现在要查询EMP 中的deptno不等于DEPTNO的deptno项. 解析: select distinct DEPTNO from EMP where DEPTNO not in ( select DEPTNO from DEPT ) 注意: 因为需要查询的是DEPTNO,所以需要排除掉重复项. 其次上面的写法,如果DEPTNO在DEPT有null项上面的是错误的.…
测试必备的Mysql常用sql语句,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1683347.html 前言 group by 关键字可以根据一个或多个字段对查询结果进行分组 group by 一般都会结合Mysql聚合函数来使用 如果需要指定条件来过滤分组后的结果集,需要结合 having 关键字:原因:where不能与聚合函数联合使用 group by 语法格式 GROUP BY <字段名>[,<…