mysql常用函式及關鍵字彙總

2022-06-27 12:24:08 字數 2269 閱讀 2031

關鍵字

1...mysql包含之in

select count(1) as count from 表名 a,表名 b where a.主鍵 = b.外來鍵  and a.欄位 in('1','2,'3') and  a.欄位<> 1;

2.and與or的結合使用

update 表名set 欄位1= 99,s欄位2 = 1 where (欄位3= '1' and 欄位4 <> '99') or (s欄位5<>1 and 欄位6 = 99) ;

3.instr與in

update sr表名 set  sys_spzt = 0 where mhzsfz in (342623199709098090 , 3301026410244561245 ,  33010252 , 3301120252);

update sr_main_ww  set  sys_spzt = 0 where  instr('33011203022252,3301120252', mhzsfz) >= 1

select count(1) as ncount from dsr_hc_jz where jsfcb = 1 and (instr(jycbm,'dsr_hc_rs')>0 or instr(jycbm,'dsr_hc_gjj')>0) and sys_zdrq like concat(?,'%')

select * from 表名 where 欄位1= 1 and 欄位2 = 0 and (欄位3= '' or 欄位4 is null or 欄位5 = '' or 欄位6 is null or 欄位7= '' or 欄位8 is null) and instr('db_jz,kn_jz,wb_jz',欄位9) > 0;

4.not in的使用

select 學生學號 from 表名 where  學生學號 not in(select 學生學號 from  表名2 a,表名3 b where a.主鍵= b.外來鍵 and a.學生學號= b.學生學號);

5.concat 拼接字串

-- 日期函式

select current_date,current_time,current_timestamp,year(current_date),month(current_date),sysdate();

select * from sr_main where timestampdiff(day,sys_createtime,sysdate())>7 and sys_spzt <>1 ;

select timestampdiff(day,'2020-02-9',sysdate());

select timestampdiff(day,'2020-02-9 17:09:39',sysdate());

其他函式:

1.round,保留2位小數第二個引數則寫2

select round(sum(mzjzje)/10000,2) as bmje207  from shjz_sjzhk_da a where sjbfnf = ? and xzqh like '33%' and instr('ywgl_sylbzj',a.mdjlx)>0 and sys_scbj =0

2.sum、ifnull、timestampdiff的使用(比如介面的平均呼叫的返回時間計算)

select

count,

(zsj / count) as pjdysj

from

(select

count(1) as count,

ifnull(

sum(

timestampdiff(day, a.dtjrq, b.rksj)),0

) as zsj

from

dsr_hc_bm a,

dsr_hc_hy b

where

a.dbmbh = 'dsr_hc_hy'

and a.dtjrq like concat('2019', '%')

and b.rksj like concat('2019', '%')

and a.dhcid = b.hyhcid

) c3.date_format的使用

//根據身份證年齡計算

select

count(1) as count

from

bd_user

where

date_format(now(), '%y') - substring(usfz, 7, 4) >=0

and date_format(now(), '%y') - substring(usfz, 7, 4) <=18

and utype = 999

ANSI ISO C 關鍵字(彙總)

彙總 auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct...

C語言關鍵字 彙總

宣告 本文為個人總結借鑑 c語言 c語言深度剖析 陳正衝 主要以深度剖析為主,自己過了一遍基礎所得。c語言關鍵字 即c語言語法已經實現直接呼叫的字,例如詞語,每個詞語一定定義了意思,直接用就行了。借鑑 c語言深度剖析 一書一共有32個關鍵字 分別為 char short int float doub...

常用庫函式及關鍵字

c語言32個關鍵字 第一類 資料型別關鍵字 a基本資料型別 5個 void 宣告函式無返回值或無引數,宣告無型別指標,顯式丟棄運算結果 char 字元型型別資料,屬於整型資料的一種 int整型資料,通常為編譯器指定的機器字長 float 單精度浮點型資料,屬於浮點資料的一種,小數點後儲存6位。dou...