zoukankan      html  css  js  c++  java
  • MariaDB 求和,最大值,最小值,平均数

    MariaDB 求和,最大值,最小值,平均数

    -----------------------------------------------

    Functions Description

    -----------------------------------------------

    AVG() Returns a column’s average value

    COUNT() Returns the number of rows in a column

    MAX() Returns a column’s highest value

    MIN() Returns a column’s lowest value

    SUM() Returns the sum of a column’s values

    -----------------------------------------------


    AVG()

    (jlive)[crashcourse]>SELECT AVG(prod_price) AS avg_price FROM products WHERE vend_id = 1003;

    +-----------+

    | avg_price |

    +-----------+

    | 13.212857 |

    +-----------+

     

    1 row in set (0.00 sec)

    (jlive)[crashcourse]>SELECT AVG(DISTINCT prod_price) AS avg_price FROM products WHERE vend_id = 1003;

    +-----------+

    | avg_price |

    +-----------+

    | 15.998000 |

    +-----------+

     

    1 row in set (0.00 sec)


    COUNT()

    (jlive)[crashcourse]>SELECT COUNT(*) AS num_cust FROM customers;

    +----------+

    | num_cust |

    +----------+

          5 |

    +----------+

    1 row in set (0.00 sec)

    统计表中总共多少行


    (jlive)[crashcourse]>SELECT COUNT(cust_email) AS num_cust FROM customers;

    +----------+

    | num_cust |

    +----------+

          3 |

    +----------+

     

    1 row in set (0.00 sec)

    统计表中cust_email字段非空的总行数


    SUM()

    (jlive)[crashcourse]>SELECT SUM(item_price*quantity) AS total_price FROM orderitems WHERE order_num = 20005;

    +-------------+

    | total_price |

    +-------------+

        149.87 |

    +-------------+

     

    1 row in set (0.00 sec)




    (jlive)[crashcourse]>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;

    +-----------+-----------+-----------+-----------+

    | num_items | price_min | price_max | price_avg |

    +-----------+-----------+-----------+-----------+

          14 |      2.50 |     55.00 | 16.133571 |

    +-----------+-----------+-----------+-----------+

     

    1 row in set (0.00 sec)

  • 相关阅读:
    docker-redis
    docker-nginx
    docker-tomcat
    JQuery/JS插件 jsTree加载树,预先加载,初始化时加载前三级节点,当展开第三级节点时 就加载该节点下的所有子节点
    Python json
    Python 模拟鼠标
    Python 取列表的前几个
    winfrom 图片等比例压缩
    winfrom 改变图片透明度 Alpha
    winform 实现类似于TrackBar的自定义滑动条,功能更全
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814188.html
Copyright © 2011-2022 走看看