SQL的詳細語法介紹——對于學習數據庫最基礎知識二
2024-07-21 02:11:14
供稿:網友
聚集函數count
用途:
傳回選取的結果集中行的數目。
語法:
select count(column_name) from table_name
例:
“persons”表中原始數據如下:
name
age
hansen, ola
34
svendson, tove
45
pettersen, kari
19
選取記錄總數:
select count(name) from persons
執行結果:
3
sum
用途:
以表達式傳回所有值的總和,或僅 distinct 值。sum 僅可用于數值資料行。已忽略 null 值。
語法:
select sum(column_name) from table_name
例:
“persons”表中原始數據如下:
name
age
hansen, ola
34
svendson, tove
45
pettersen, kari
19
選取”persons”表中所有人的年齡總和:
select sum(age) from persons
執行結果:
98
選取”persons”表中年齡超過20歲的人的年齡總和:
select sum(age) from persons where age>20
執行結果:
79
avg
用途:
傳回選取的結果集中值的平均值。已忽略 null 值。
語法:
select avg(column_name) from table_name
例:
“persons”表中原始數據如下:
name
age
hansen, ola
34
svendson, tove
45
pettersen, kari
19
選取”persons”表中所有人的平均年齡:
select avg(age) from persons
執行結果:
32.67
選取”persons”表中年齡超過20歲的人的平均年齡:
select avg(age) from persons where age>20
執行結果:
39.5
max
用途:
傳回選取的結果集中值的最大值。已忽略 null 值。
語法:
select max(column_name) from table_name
例:
“persons”表中原始數據如下:
name
age
hansen, ola
34
svendson, tove
45
pettersen, kari
19
選取”persons”表中的最大年齡:
select max(age) from persons
執行結果:
45
min
用途:
傳回選取的結果集中值的最小值。已忽略 null 值。
語法:
select min(column_name) from table_name
例:
“persons”表中原始數據如下:
name
age
hansen, ola
34
svendson, tove
45
pettersen, kari
19
選取”persons”表中的最小年齡:
select min(age) from persons
執行結果:
19
算術函數abs
用途:
傳回指定數值表達式 (numeric expression) 的絕對正值。
語法:
abs(numeric_expression)
例:
abs(-1.0) abs(0.0) abs(1.0)
執行結果:
1.0 0.0 1.0
ceil
用途:
傳回大于等于給定數值表達式的最小整數。
語法:
ceil(numeric_expression)
例:
ceil(123.45) ceil(-123.45)
執行結果:
124.00 -123.00
floor
用途:
傳回小于或等于給定數值表達式的最大整數。
語法:
floor(numeric_expression)
例:
floor(123.45) floor(-123.45)
執行結果:
123.00 -124.00
cos
用途:
在指定表達式中傳回指定角度 (以弳度為單位) 的三角余弦值的數學函數。
語法:
cos(numeric_expression)
例:
cos(14.78)
執行結果:
-0.599465
cosh
用途:
傳回以弧度為單位的角度值,其余弦為指定的 float 表達式,也稱為反余弦。
語法:
cosh(numeric_expression)
例:
cosh(-1)
執行結果:
3.14159
sin
用途:
以近似的數值 (float) 表達式傳回給定角度 (以弧度) 之三角正弦函數 (trigonometric sine)。
語法:
sin(numeric_expression)
例:
sin(45.175643)
執行結果:
0.929607
sinh
用途:
傳回以弳度為單位的角度,其正弦為指定的 float 表達式 (也稱為反正弦)。
語法:
sinh(numeric_expression)
例:
sinh(-1.00)
執行結果:
-1.5708
tan
用途:
傳回輸入表達式的正切函數。
語法:
tan(numeric_expression)
例:
tan(3.14159265358979/2)
執行結果:
1.6331778728383844e+16
tanh
用途:
傳回以弳度為單位的角度,其正切為指定的 float 表達式 (也稱為反正切)。
語法:
tanh(numeric_expression)
例:
tanh(-45.01)
執行結果:
-1.54858
exp
用途:
傳回給定的 float 表達式的指數 (exponential) 值。
語法:
exp(numeric_expression)
例:
exp(378.615345498)
執行結果:
2.69498e+164
log
用途:
傳回給定的 float 表達式之自然對數。
語法:
log(numeric_expression)
例:
log(5.175643)
執行結果:
1.64396
power
用途:
傳回給定表達式指定乘冪的值。
語法:
power(numeric_expression,v)
例:
power(2,6)
執行結果:
64
sign
用途:
傳回給定的表達式之正 (+1)、零 (0) 或負 (-1) 號。
語法:
sign(numeric_expression)
例:
sign(123) sign(0) sign(-456)
執行結果:
1 0 -1
sqrt
用途:
傳回給定表達式的平方。
語法:
sqrt(numeric_expression)
例:
sqrt(10)
執行結果:
100