zoukankan      html  css  js  c++  java
  • MariaDB Grouping

    MariaDB Grouping

    (jlive)[crashcourse]>SELECT vend_id, COUNT(*) AS num_prods FROM products GROUP BY vend_id WITH ROLLUP;

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

    | vend_id | num_prods |

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

      1001 |         3 |

      1002 |         2 |

      1003 |         7 |

      1005 |         2 |

      NULL |        14 |

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

    5 rows in set (0.00 sec)

    (jlive)[crashcourse]>SELECT vend_id, COUNT(*) AS num_prods FROM products GROUP BY vend_id HAVING COUNT(*) >= 2;

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

    | vend_id | num_prods |

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

      1001 |         3 |

      1002 |         2 |

      1003 |         7 |

      1005 |         2 |

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

     

    4 rows in set (0.00 sec)



    (jlive)[crashcourse]>SELECT vend_id, COUNT(*) AS num_prods FROM products WHERE prod_price >= 10 GROUP BY vend_id HAVING COUNT(*) >= 2;

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

    | vend_id | num_prods |

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

      1003 |         4 |

      1005 |         2 |

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

     

    2 rows in set (0.00 sec)



    (jlive)[crashcourse]>SELECT order_num, SUM(quantity*item_price) ordertotal FROM orderitems GROUP BY order_num HAVING ordertotal >= 50 ORDER BY 2 DESC;

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

    | order_num | ordertotal |

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

    |     20007 |    1000.00 |

    |     20005 |     149.87 |

    |     20008 |     125.00 |

    |     20006 |      55.00 |

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

     

    4 rows in set (0.00 sec)

      


    (jlive)[crashcourse]>SELECT order_num, SUM(quantity*item_price) AS ordertotal FROM orderitems GROUP BY order_num HAVING SUM(quantity*item_price) >= 50 ORDER BY ordertotal DESC LIMIT 2 OFFSET 1;

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

    | order_num | ordertotal |

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

    |     20005 |     149.87 |

    |     20008 |     125.00 |

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

     

    2 rows in set (0.00 sec)

  • 相关阅读:

    JVM基础
    rpm、yum、解压缩安装
    Vim使用及账号用户管理
    linux常用操作
    属主权限和属组权限
    解决Hystrix Dashboard 一直是Loading ...的情况
    扫描不到了@FeignClient注解的调用接口
    springcloud与springboot版本问题
    【力扣】6和9组成的最大数字 题解
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814186.html
Copyright © 2011-2022 走看看