self_example/SQL_example/内置函数.sql

17 lines
459 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

##
SELECT COUNT(*) AS num FROM emp;
## 40
SELECT COUNT(*) FROM emp WHERE age>40;
# sum()
SELECT SUM(age) FROM emp
# avg():
SELECT AVG(age) FROM emp
##
SELECT AVG(age) AS avgnum FROM emp
#cast转换类型
SELECT CAST(AVG(age) AS DECIMAL(10,2)) AS avgnum FROM emp
#
SELECT MAX(age) FROM emp;
SELECT MIN(age) FROM emp;