易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL精华收集

order by 的数值型灵活使用
select * from table_a where id=p_id order by decode(函数,'asc',1,'desc',-1)*jsny;
控制试图的访问时间:
6.create view ...
as
select ... from where exists(select x from dual where sysdate>=8:00am and sysdate<=5:00pm)
妙用decode实现排序
select * from tabname
order by decode(mode,'FIFO',1,-1)*to_char(rq,'yyyymmddhh24miss');
select * from tabname
order by decode(mode,'FIFO',rq-sysdate, sysdate-rq)
找出某个时期内工作日数:
select count(*)
from ( select rownum-1 rnum
from all_objects
where rownum <= to_date('2002-02-28','yyyy-mm-dd') - to_date('2002-
02-01','yyyy-mm-dd')+1 )
where to_char( to_date('2002-02-01','yyyy-mm-dd')+rnum-1, 'D' ) not
in ( '1', '7' )
我觉得查询重复记录的语句就很经典
select rowid,bdsszd from BADWDJ a where a.rowid != (select max(rowid) from BADWDJ b where a.bdsszd =b.bdsszd)
由它引申的就有很多有用的语句,如昨天回答别人的排序的难题
select id,bdsszd from BADWDJ a where a.id = (select max(id) from BADWDJ b where a.bdsszd =b.bdsszd) order by id
树型结构表的查询:
select ID,PARENT_ID from parent_child
connect by prior id = parent_id
start with id = 1;
1.decode这个函数一定需要会,我觉得sql的灵活很多地方都是通过这个function来体现的,相当于if,很好用。
2.group by,这个东东想想简单,其实好多统计功能是离不开这个操作的。oracle8中扩充了group by rollup和cube的操作。有时候省了你好多功夫的。值得注意的是,当你对事物做过有效的人为归并之后执行group by 往往会更让人心旷神怡。
3.很表竖置的经典写法,也要记住:sum(decode( )) group by ...
注意:需要在一个subquery中确定一个横置判点。
4.树形结构表的遍历写法:select ...from ....
start with ... connect by prior (父子关系表达式)
select * from xxx where decode(:var,null,'0',column1) = decode(:var,null,'0',:var);
816以上的 一些分析函数如 rank() over() and row_number() over()
当然关于 group by rollup/cube使用的人恐怕特别少
如何实现最大匹配的操作?
例如:给定字符串 '1234', 而表中可能有记录项'1','12','123','1234','12345',要选出'


相关文档:

SQL Server Compact 3.5 SP2已经发布

随着Visual Studio 2010的发布,Microsoft SQL Server Compact 3.5也升级为Microsoft
SQL Server Compact SP2。
下载地址如下:
SQL
Server Compact 3.5 SP2 for Windows mobile devices (all platforms &
processors)
 
SQL
Server Compact 3.5 SP2 for Windows desktop (32-bit and 64-bit)
  ......

SQL求解八皇后问题(92种结果)

--该表保存结果
create table c(c1 tinyint, c2 tinyint, c3 tinyint, c4 tinyint, c5 tinyint, c6 tinyint, c7 tinyint, c8 tinyint, c9 tinyint, c10 tinyint, c11 tinyint, c12 tinyint, c13 tinyint, c14 tinyint, c15 tinyint, c16 tinyint, c17 tinyint, c18 tinyint, c19 tinyint, c20 tinyint, c21 tinyint, c22 t ......

pl/sql 语句的几点优化

1.
     SQL> desc gjh_a05 ;
Name  Type          Nullable Default Comments
----- ------------- -------- ------- --------
A0500 VARCHAR2(2)   Y           &nbs ......

基于SQL的分页

select top PageSize * from 表
where 条件 and id not in
(select top PageSize*(CurrentPageIndex-1)  id from 表 where 条件 order by 排序条件)
order by 排序条件
《PageSize 是GridView中每页显示的信息条数,PageSize*(CurrentPageIndex-1) 在SQL中不识别,需定义变量来替换》 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号