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)

  • 相关阅读:
    mysql常用函数
    mysql中utf8_bin、utf8_general_ci、utf8_general_cs编码区别
    JS 中的return false的作用
    css3 animation动画执行结束,停顿几秒后重新开始执行
    (原)人月神话-阅读笔记
    (原创)cocosStudio: text设置颜色问题
    (原创)cocos-js js调用android
    (原创)cocos-js 实现震屏效果
    (转)Cocos2d-js中使用Shader方法--以一个简单的波纹效果为例:
    (转)Cocos2dx-JS 在 Sprite 上使用 Shader
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814186.html
Copyright © 2011-2022 走看看