Group functions
SELECT [column,] group_function(column) ... from table [WHERE condition] [GROUP BY group_by_expression] [ORDER BY column];
e.g.:
SELECT department_id, job_id, SUM(salary), COUNT(employee_id) from employees GROUP BY department_id, job_id ;
SELECT [column,] group_function(column)... from table [WHERE condition] [GROUP BY group_by_expression]
[HAVING having_expression] [ORDER BY column];
GROUP BY with ROLLUP and CUBE Operators
1. Use ROLLUP or CUBE with GROUP BY to produce superaggregate rows by cross-referencing columns.
2. ROLLUP grouping produces a result set containing the regular grouped rows and the subtotal values.
3. CUBE grouping produces a result set containing the rows from ROLLUP and cross-tabulation rows.
SELECT [column,] group_function(column). . .from table [WHERE condition] [GROUP BY [ROLLUP] group_by_expression] [HAVING having_expression];[ORDER BY column];
//ROLLUP is an extension to the GROUP BY clause Use the ROLLUP operation to produce cumul ......
oracle tips
Exist的用法:
select gw.ndocid from
(select ndocid from wf_doc_gw_shouwen union select ndocid from wf_doc_gw_fawen) gw
where
not exists (select null from wf_doc_gw_sn sn where sn.ndocid=gw.ndocid)
2。把GW表和SN表里相同的NDOCID显示出来
select gw.ndocid from
(select ndocid from wf_doc_gw_shouwen union select ndocid from wf_doc_gw_fawen) gw
where
exists (select null from wf_doc_gw_sn sn where sn.ndocid=gw.ndocid)
DECODE的语法:DECODE(value,if1,then1,if2,then2,if3,then3,...,else),
e.g.:
select decode(max(documentid), null, 1, (max(documentid)+1))) from document;
results:
if null, display 1
else display max(documentid)+1
1. export database
cmd
%oracle_home%\bin\exp carmot/carmot@132.159.178.236_igrp2 file=d:\a.dmp
2. oracle enterprise console
connect as sysdba
安全性,右键,建立用户carmot_hunan_1,密码用carmot
给dba权限。
3. import database
cmd
%oracle_home%\bin\imp carmot_hun ......
1. My test: (create and grant the sysdba to a new user by SQL*Plus)
CREATE USER FJTEST1 IDENTIFIED BY JEANJEANFANG;
GRANT SYSDBA TO FJTEST;
REVOKE SYSDBA from FJTEST;
CONNECT FJTEST1/JEANJEANFANG AS SYSDBA;
2. Using ORAPWD in windows:
C:\» ORAPWD;
(show help information)
3. to see the password file:
Grammer: ORACLE_BASE\ORACLE_HOME\database» attrib
F:\oracle\ora92\database\attrib
** if want to create a user that can be connect as normal and can create table, you should grant “create session”, “resource” privileges to the user or it cannot connect as normal.
e.g.:
SQL»create user fj identified by fj;
SQL»grant create session to fj;
SQL»grant resource to fj;
Then the user “fj” can be connected as “normal” and the schema belonging to this user will be created, where he/she can create tables.
SQL» select * from user_sys_privs;
Use above statements to check user’s own system privile ......
在程序的开发过程中,处理分页是大家接触比较频繁的事件,因为现在软件基本上都是与数据库进行挂钓的。但效率又是我们所追求的,如果是像原来那样把所有满足条件的记录全部都选择出来,再去进行分页处理,那么就会多多的浪费掉许多的系统处理时间。为了能够把效率提高,所以现在我们就只选择我们需要的数据,减少数据库的处理时间,以下就是常用SQL分页处理:
1、SQL Server、Access数据库
这都微软的数据库,都是一家人,基本的操作都是差不多,常采用如下分页语句:
PAGESIZE:每页显示的记录数
CURRENTPAGE:当前页号
数据表的名字是:components
索引主键字是:id
以下是引用片段:
select top PAGESIZE * from components where id not in
(select top (PAGESIZE*(CURRENTPAGE-1))
id from components order by id)order by id
如下列:
以下是引用片段:
select top 10 * from components where id not in
(select top 10*10 id&nbs ......
在程序的开发过程中,处理分页是大家接触比较频繁的事件,因为现在软件基本上都是与数据库进行挂钓的。但效率又是我们所追求的,如果是像原来那样把所有满足条件的记录全部都选择出来,再去进行分页处理,那么就会多多的浪费掉许多的系统处理时间。为了能够把效率提高,所以现在我们就只选择我们需要的数据,减少数据库的处理时间,以下就是常用SQL分页处理:
1、SQL Server、Access数据库
这都微软的数据库,都是一家人,基本的操作都是差不多,常采用如下分页语句:
PAGESIZE:每页显示的记录数
CURRENTPAGE:当前页号
数据表的名字是:components
索引主键字是:id
以下是引用片段:
select top PAGESIZE * from components where id not in
(select top (PAGESIZE*(CURRENTPAGE-1))
id from components order by id)order by id
如下列:
以下是引用片段:
select top 10 * from components where id not in
(select top 10*10 id&nbs ......
在程序的开发过程中,处理分页是大家接触比较频繁的事件,因为现在软件基本上都是与数据库进行挂钓的。但效率又是我们所追求的,如果是像原来那样把所有满足条件的记录全部都选择出来,再去进行分页处理,那么就会多多的浪费掉许多的系统处理时间。为了能够把效率提高,所以现在我们就只选择我们需要的数据,减少数据库的处理时间,以下就是常用SQL分页处理:
1、SQL Server、Access数据库
这都微软的数据库,都是一家人,基本的操作都是差不多,常采用如下分页语句:
PAGESIZE:每页显示的记录数
CURRENTPAGE:当前页号
数据表的名字是:components
索引主键字是:id
以下是引用片段:
select top PAGESIZE * from components where id not in
(select top (PAGESIZE*(CURRENTPAGE-1))
id from components order by id)order by id
如下列:
以下是引用片段:
select top 10 * from components where id not in
(select top 10*10 id&nbs ......
(注:outer的意思就是"没有关联上的行"。)
1.cross join 全外连接(笛卡尔乘积)
SELECT A.*, B.* from A FULL OUTER JOIN B ON A.ID = B.ID
2.inner join 内连接(在笛卡尔乘积的结果集中去掉不符合连接条件的行)
SELECT A.* from A INNER JOIN B ON A.ID=B.ID
3.left outer join 左外连接(在inner join的结果集上加上左表中没被选上的行,行的右表部分每个字段都用NUll填充)
SELECT A.* from A LEFT JOIN B ON A.ID = B.ID
4.right outer join 右外连接(在inner join的结果集上加上右表中没被选上的行,行的左表部分全用NULL填充。)
SELECT A.* from A RIGHT JOIN B ON A.ID = B.ID
举例说明:
表A
记录如下:
aID aNum
1 a20050111
2 a20050112
3   ......
--> Title : SQL Server系统视图
--> Author : wufeng4552
--> Date : 2009-10-28
目录视图
目录视图返回 SQL Server 数据库引擎使用的信息。建议您使用目录视图这一最常用的目录元数据界面,它可为您提供最有效的方法来获取、转换并显示此信息的自定义形式。所有用户可用目录元数据都通过目录视图来显示。
注意:目录视图不包含有关复制、备份、数据库维护计划或 SQL Server 代理目录数据的信息。
某些目录视图从其他目录视图继承行。例如,sys.tables 目录视图继承自 sys.objects 目录视图。sys.objects 目录视图称为基本视图,而 sys.tables 视图称为派生视图。sys.tables 目录视图返回专用于表的列,同时还返回 sys.objects 目录视图返回的所有列。sys.objects 目录视图返回表之外的对象(例如,存储过程和视图)的行。创建表之后,表的元数据将在两个视图中返回。尽管两个目录视图返回有关表的不同级别的信息,但在此表的元数据中只有一个具有一个名称和一个 object_id 的项。这可以总结如下:
基本视图包含列的子集和行的超集。
派生视图包含列的超集和行的子集。
SQL Server 中的目录视图具有如下类别:
更改跟踪目录 ......