现在的位置: 首页 > 综合 > 正文

select 常用语句

2013年03月27日 ⁄ 综合 ⁄ 共 1004字 ⁄ 字号 评论关闭

select 用法   select * from test (显示所以字段)  

select count(*) from test (统计test表中的记录)   

select id, name from test(显示部分字段)   

select id 学号, name 姓名 from test (取别名)   

select * from test where id='007'(显示直到信息)  

select * from test where name in=('007','008') (in 用法)  

select  a.id1,a.name2 from  test1  a  where  not exists (select  * from  test2 b where  b.name2=a.name2)  (exists用法)   

select distinct name from test (名字不重复)   

select * from test order by id desc(按id升序)  

select * from test order by id asc (默认)

select * from test order by 2 desc (2 表示第2列)   

select * from TBL_TEST start with id=1 connect by prior id = pid (树表查询)  

select * from (select * from test order by num asc ) where rownum <3  (显示表中前三条 )   

select id,name from test group by id,name (按id,name分组)   

select id,name from test group by 1,2 (按id,name分组)   

select num,name  from test group by num,name having count(*)>1   

select  id table a,(select id,name count(*) from table group by id,name having count(1)>1) b  where b.id=b.id and a.name=b.rg group by id,rg (显示重复记录)   

 select t1.id id,ti.name name,t2.oder oder1,t3.oder oder2 from test1 t1,test2 t2,test3 t3 where t1.name(+)=t2.name t1.name(+)=t3.name    (左右关联)     

抱歉!评论已关闭.