• 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)

  • 相关阅读:
    git
    node cheerio
    Git是目前世界上最先进的分布式版本控制系统
    精华 ionic入门之色彩、图标、边距和界面组件:列表
    如何将腾讯视频的qlv格式转换为mp4格式
    php无限级分类实战——评论及回复功能
    Yii2 前后台登陆退出分离、登陆验证
    linux 更改文件所属用户及用户组
    wdcp 开启某个Mysql数据库远程访问
    Rem实现自适应初体验
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814186.html
Copyright © 2020-2023  润新知