zoukankan      html  css  js  c++  java
  • 《mysql必知必会》学习_第12章

    第12章:汇总数据

     P76 avg()函数求平均值

    select avg(prod_price) as avg_price from products; #计算prod_price的平均值,并且命名为avg_price#

     select avg(prod_price) as avg_price from products where vend_id=1003; #计算priod_id=1003的prod_price的平均值,并且命名为avg_price#

    select count(*) as num_cust from customers;  #通配符*表示选中所有行,包括空值,返回是行数。#

     select count(cust_email) as num_cust from customers; #计算行cust_email的个数,不包括空值#

     select max(prod_price) as max_price from products; #max()计算列prod_price的最大数#

     P79 min()函数用来计算最小值,经常也计算最初的时间。

    select min(prod_price) as min_price from products; #计算prod_price的最小值,并命名为min_price#

     select sum(quantity) as items_ordered from orderitems where order_num=2005; #sum()函数计算括号里面的列中订单号码等于20005的数值的总值#

     P80

      select sum(quantity*item_price) as total_price from orderitems where order_num=2005; #sum()函数计算括号里面的列中订单号码等于20005的数值的总值#

     

    P81 聚集不同值

    select avg(distinct prod_price) as avg_price from products where vend_id=1003; #distinct 表示去掉重复值,然后再求去掉重复值之后的平均值,并命名为avg_price ,条件是vend_id=1003#

    注意:没有count(distinct)的使用,有distinct(count)的使用。

    select count(*) as num_items, min(prod_price) as price_min,max(prod_price) as price_max,avg(prod_price) as price_avg from products;   #一个语句中同时出现几个语句#

  • 相关阅读:
    转战博客园
    C++虐恋:MBCS安装失败导致的四天误工
    Servlet 3.0 新特性详解 (转载)
    数据库连接池proxool的两种使用方式
    java异常处理中的细节
    InvocationTargetException异常的深入研究-servlet的setAttribute与getAttribute
    如果我是一个全栈极客,那么,下一步该怎么走?
    C++基础与提高 001
    用户及文件权限管理
    命令行操作体验
  • 原文地址:https://www.cnblogs.com/qiyuanjiejie/p/9407073.html
Copyright © 2011-2022 走看看