[Oracle]高效的SQL语句之分析函数(一)
本系列文章导航
[Oracle]高效的SQL语句之分析函数(一)--sum()
[Oracle]高效的SQL语句之分析函数(二)--max()
[Oracle]高效的SQL语句之分析函数(三)--row_number() /rank()/dense_rank()
[Oracle]高效的SQL语句之分析函数(四)--lag()/lead()
实际应用中我们可以通过sum()统计出组中的总计或者是累加值,具体示例如下:
1.创建演示表
create table emp
as
select * from scott.emp;
alter table emp
add constraint emp_pk
primary key(empno);
create table dept
as
select * from scott.dept;
alter table dept
add constraint dept_pk
primary key(deptno);
2. sum()语句如下:
select deptno,
ename,
sal,
--按照部门薪水累加(order by改变了分析函数的作用,只工作在当前行和前一行,而不是所有行)
sum(sal) over (partition by deptno order by sal) CumDeptTot,
sum(sal) over (partition by deptno) SalByDept, --统计一个部门的薪水
sum(sal) over (order by deptno,sal) CumTot, --所有雇员的薪水一行一行的累加
sum(sal) over () TotSal --统计总薪水
from emp
order by deptno, sal
3. 结果如下:
10 MILLER 1300.00 1300 8750 1300 29025
10 CLARK 2450.00 3750 8750 3750 29025
10 KING 5000.00 8750 8750 
相关文档:
在查询分析器中输入以下内容:
set statistics profile on
set statistics io on
set statistics time on
go
go
set statistics profile off
set statistics io off
set statistics time off ......
在Excel中,我们时常会碰到这样的字段(最常见的就是电话号码),即有纯数字的(如没有带区号的电话号码),又有数字和其它字符混合 (如“区号-电
话号码”)的数据,在导入SQLServer过程中,会发现要么纯数字的数据导过去之后变成了NULL,要么就是数字和其它字符混合的数据导过去之后变成
了NULL。
&n ......
SQL注入简单分析
示例语句:
select * from admintable where adminName like '%a%'
在查询中我们一般在a这个地方由界面传入不同的值,当我们在a这里传入的值为“'”单引号时,拼凑成的SQL语句就如下:
select * from admintable where adminName like '%'%'
执行这句语句我们会发现出现以下异常:
......
在使用ODP.NET进行Oracle编程时,有时候SQL语句非常复杂,需要采用动态构造查询语句的情况,有两种方法可以构造动态的SQL语句,并执行返回结果集。
1、在数据访问层构造SQL语句
例如下面的语句,将构造完整的SQL语句赋值给CommandText,再传递到数据库进行执行,返回结果集。
loadCommand.CommandType = Com ......