SQL的查詢操作語句

2021-07-09 04:49:51 字數 1390 閱讀 6052

近來在寫sql,發現能寫一些複雜的sql可以很大的提高工作的效率。今天趁著有時間整理一下,方便以後用到的時候查詢:

1、對特定的條件加和操作

select sum(列名) from 表名 where 列名='條件'

2、對加和的資料再次進行加和,並且使用資料的空表

select c1+c2+c3 from (

select

(select count(列名1) from 表名1 where 列名4='條件1') as c1,

(select count(列名2) from 表名2 where 列名5='條件2') as c2,

(select count(列名3) from 表名3 where 列名6='條件3') as c3

from dual

)

3、根據條件進行加和操作

select count(列名) from 表名 where 

列名=條件1

and (列名 like '條件2' or 列名 like '條件3')

and (trunc(months_between(sysdate,to_date(csny,'yyyy-mm'))/12) <= 45)

4、將選擇的結果進行拼裝

select concat(concat(c1,'('),concat(decode(c2,0,0,c1/c2),')'))

from

(select

(select count(列名) from 表名 where 列名=條件) as c1,

(select count(列名) from 表名) as c2

from dual

)

5、group by 和order by以及降序選擇

select 列名 ,count(列名) as c1  

from 表名 where 列名=條件

group by 列名

order by 列名

asc

6、rownum、cast在sql中用法

select 列名,列名 from 表名 where 列名=條件 

and rownum <=5

order by cast(列名 as integer)

desc

7、在sql中使用正規表示式

select 列名 from 表名 where 列名='條件' and regexp_like(列名,'正則規則')

sql倒序查詢語句 常見的SQL查詢語句

檢視會話數 select count from v session 檢視程序數 select count from v process 檢視資料庫的併發連線數 select from v session where status active 檢視當前資料庫建立的會話 select sid,seri...

sql 語句 查詢

例11 1 1 use xk gocreate trigger test1 on student for update as print 記錄已修改!go 2 update student set pwd 11111111 where stuno 00000001 例11 3 1 use xk go...

SQL查詢語句

create or replace procedure imms pk reportsend fromdate varchar2,todate varchar2 as function 系統效能統計 author qja 功能 將imms statusreport 表和imms report sen...