zoukankan      html  css  js  c++  java
  • MySql学习笔记(三) —— 聚集函数的使用

    1.AVG() 求平均数

    select avg(prod_price) as avg_price from products; --返回商品价格的平均值
    
    select avg(prod_price) as avg_price from products where vend_id = 1003; --返回生产商id为1003的商品价格平均值

    2.COUNT():确定表中行的数目或者符合特定条件的行的数目

    select count(*) as num_cust from customers; --统计customers表中的顾客数
    select count(email) as num_cust from customers; --统计具有邮件的用户数目

    3.max():返回指定列中的最大值

    select max(prod_price) as max_price from products; --返回价格最大值

    它能够返回任意列的最大值,如果是文本数据时,会返回最后一行。

    4.min():返回指定列的最小值

    select min(prod_price) as max_price from products; --返回价格最小值

    它能够返回任意列的最小值,如果是文本数据时,会返回最前面的行。

    5.sum():返回指定列值的和

    select sum(quantity) as items_ordered from orderitems where order_num = 20005;  --返回订单编号为20005所订购的商品总数
    select sum(item*quantity) as total_price from orderitems where order_num = 20005;  --返回订单编号为20005所订购的商品总额
  • 相关阅读:
    二叉查找树
    二叉树
    广度优先搜索
    深度优先搜索
    algorithm:next_permutation
    Grafana Labs 携手阿里云,将提供国内首款 Grafana 托管服务
    台积电TSMC一些技术特点
    TSMC台积电各种制程工艺技术
    激光雷达激烈竞争市场
    边端云处理器系列技术参数
  • 原文地址:https://www.cnblogs.com/love-Stefanie/p/6894383.html
Copyright © 2011-2022 走看看