資料庫中常用的函式都有哪些啊,資料庫常用函式

時間 2021-09-15 00:09:58

1樓:黑馬程式設計師

1.檢索資料

select prod_namefrom products;

#檢索單列

select prod_id, prod_name, prod_pricefromproducts;

#檢索多列

select * from products;

#檢索所有列

select distinctvend_id fromproducts;

#檢索不同的值

selectprod_name from products limit 5;

#返回不超過5行資料

selectprod_name from products limit 5 offset 5;

#返回從第5行起的5行資料。limit指定返回的行數,limit帶的offset指定從哪兒開始。

2.排序檢索資料

selectprod_name

fromproducts

order byprod_name;

#排序資料

select prod_id, prod_price, prod_name

fromproducts

order by prod_price, prod_name;

#按多個列排序

select prod_id, prod_price, prod_name

fromproducts

order by 2, 3;

#按列位置排序,第三行表示先按prod_price, 再按prod_name進行排序

select prod_id, prod_price, prod_name

fromproducts

order by prod_pricedesc, prod_name;

#prod_price列以降序排序,而prod_name列(在每個**內)仍然按標準的升序排序

3.過濾資料

select prod_name, prod_price

fromproducts

where prod_price< 10;

#檢查單個值

select prod_name, prod_price

fromproducts

where vend_id <> 『dll01』;

#不匹配檢查

select prod_name, prod_price

fromproducts

where prod_pricebetween 5 and 10;

#範圍值檢查

select cust_name

fromcustomers

where cust_emailis null;

#空值檢查

4.高階資料過濾

selectprod_id, prod_price, prod_name

fromproducts

where vend_id = 『dll01』andprod_price <= 4;

#and操作符

selectprod_name, prod_price

fromproducts

wherevend_id=』dll01』 or vend_id=』brs01』;

#or操作符

selectprod_name, prod_price

fromproducts

where (vend_id = 』dll01』orvend_id=』brs01』)

andprod_price >= 10;

#求值順序 and的優先順序高於or

selectprod_name, prod_price

fromproducts

where vend_idin (『dll01』,』brs01』)

order by prod_name;

#in操作符

select prod_name

fromproducts

where notvend_id = 『dll01』

order by prod_name;

#not 操作符

select prod_name

fromproducts

wherevend_id <> 『dll01』

order by prod_name;

#not 操作符

資料庫常用函式

2樓:大野瘦子

1、系統資訊函式

系統資訊函式用來查詢mysql資料庫的系統資訊。

函式**:

select version()

->5.0.67-community-nt

connection_id() 返回伺服器的連線數

database()、schema 返回當前資料庫名

user()、system_user()返回當前使用者

2、日期時間函式

mysql的日期和時間函式主要用於處理日期時間。

函式**:

curdate(),current_date() curdate() 返回當前日期

select curdate()

->2014-12-17

curtime(),current_time curtime()

返回當前時間

select curtime()

->15:59:02

3、字串函式

函式**:

char_length(s) char_length()返回字串s的字元數

select char_length('你好123') -- 5

concat(s1,s2,...) concat(s1,s2...)

將字串s1,s2等多個字串合併為一個字串

4、加密函式

加密函式是mysql用來對資料進行加密的函式。

函式**:

password(str)

該函式可以對字串str進行加密,一般情況下,password(str)用於給使用者的密碼加密。

select password('123')

->*23ae809ddacaf96af0fd78ed04b6a265e05aa257

5、數學函式

數學函式主要用於處理數字,包括整型、浮點數等。

函式**:

abs(x) abs(x)返回x的絕對值

select abs(-1) -- 返回1

ceil(x),ceiling(x) cell(x),celling(x)

返回大於或等於x的最小整數

select ceil(1.5) -- 返回2

3樓:辦公新萌圈

excel技巧:資料統計中的6個常用函式

4樓:手機使用者

一個函式類似於一個算符,它運算元據項,返回一個結果。函式在格式上不同於算符,它個具有變元,可操作0個、一個、二個或多個變元,形式為:

函式名(變元,變元,…)

函式具有下列一般類形:

◆單行函式

◆分組函式

(1)單行函式對查詢的表或檢視的每一行返回一個結果行。它有數值函式,字元函式,日期函式,轉換函式等。

(2)分組函式返回的結果是基於行組而不是單行,所以分組函式不同於單行函式。在許多分組函式中可有下列選項:

◆distrnct 該選項使分組函式只考慮變元表示式中的不同值。

◆all該選項使分組函式考慮全部值,包含全部重複。

全部分組函式(除count(*)外)忽略空值。如果具有分組函式的查詢,沒有返回行或只有空值(分組函式的變元取值的行),則分組函式返回空值。

5樓:

convert

cast

sumcount

maxmin

strsubstring

......

資料庫常用函式,常用資料庫有哪些?

大野瘦子 1 系統資訊函式 系統資訊函式用來查詢mysql資料庫的系統資訊。函式 select version 5.0.67 community nt connection id 返回伺服器的連線數 database schema 返回當前資料庫名 user system user 返回當前使用者 ...

資料庫語言有哪些,資料庫中常用的sql語句有哪些

墨汁諾 資料定義語言 ddl 例如 create drop alter等語句。資料操作語言 dml 例如 insert 插入 update 修改 delete 刪除 語句。資料查詢語言 dql 例如 select語句。一般不會單獨歸於一類,因為只有一個語句 資料控制語言 dcl 例如 grant r...

資料庫都有什麼型別的啊,請問資料庫有哪些種類呢

天融信教育科技 目前有許多資料庫產品,如oracle sybase informix microsoft sql server microsoft access visual foxpro等產品各以自己特有的功能,在資料庫市場上佔有一席之地。下面簡要介紹幾種常用的資料庫管理系統。oracle ora...