时间/日期函数 time()和date()
    date用来查询日期,用法示例

    1. SELECT * FROM `user` where DATE(create_time) = '2022-06-14'

    image.png
    image.png
    日期范围限制搜索

    1. SELECT * FROM `user` where DATE(create_time) BETWEEN
    2. '2022-06-14' AND '2022-06-20'

    image.png

    数值处理函数
    image.png
    聚集函数
    image.png

    1. SELECT AVG(salary) FROM `employees`

    使用示例
    image.png
    count(*) 返回特定列所有的行数.

    1. SELECT COUNT(*) FROM `employees`

    image.png

    1. SELECT COUNT(email) FROM `user`

    image.png
    返回有email的用户账号数据.

    一个sql里可以使用多次函数,例如

    1. SELECT
    2. COUNT( gdp ) AS world_count,
    3. AVG( gdp ) AS world_gdp
    4. FROM
    5. world

    image.png
    数组分组
    GROUP BY示例

    1. SELECT sex,COUNT(*) AS aslary_sex FROM `salary`

    image.png

    1. SELECT sex,COUNT(*) AS aslary_sex FROM `salary`
    2. GROUP BY sex

    image.png
    group by必须放置在where语句之后,order by之前.

    having 对where查询出来的数据进一步过滤.

    1. SELECT username ,COUNT(*) AS usernum FROM `userorder` WHERE orderprice > 10 GROUP BY userid

    image.png

    1. SELECT username ,COUNT(*) AS usernum FROM `userorder` WHERE orderprice > 10 GROUP BY userid
    2. HAVING
    3. COUNT( * ) > 2;

    image.png
    ORDER BY 和 GROUP BY

    1. SELECT username, SUM(orderprice) AS usernum FROM `userorder` GROUP BY userid

    image.png
    使用order by

    1. SELECT username, SUM(orderprice) AS usernum FROM `userorder` GROUP BY userid ORDER BY usernum

    image.png
    依照和的大小排序.
    image.png