"MYSQL" Select from Group by

Source: Internet
Author: User

    • GROUP BY
Mysql> SELECT * from t_user GROUP by LVL; +-----+-------+----------+------+--------+| UID | uname | Tel      | lvl  | salart |+-----+-------+----------+------+--------+|   1 | Alex  | 23131231 | A    |   1100 | |   3 | Kit   | 87416574 | B    |   | |   4 | Poker | 41874521 | C    |   1560 |+-----+-------+----------+------+--------+mysql> select lvl from T_user group by LVL; +------+| LVL  |+------+| A    | | B    | | C    |+------+
    • Group by + Group_concat ()
Mysql>Select Lvl,group_concat (salart) from T_user Group by LVL;+------+----------------------+| Lvl | Group_concat (Salart) |+------+----------------------+| A | 1100,4300 | | B | 1200 | | C | 1560 |+------+----------------------+3 rowsinchSet (0.00sec) MySQL>Select Lvl,group_concat (UID) as salary from T_user Group by LVL;+------+--------+| Lvl | Salary |+------+--------+| A | | | B | 3 | | C | 4 |+------+--------+3 rowsinchSet (0.00sec) MySQL>Select Lvl,group_concat (salart) from T_user Group by LVL;+------+----------------------+| Lvl | Group_concat (Salart) |+------+----------------------+| A | 1100,4300 | | B | 1200 | | C | 1560 |+------+----------------------+3 rowsinchSet (0.00sec) MySQL>Select Lvl,group_concat (Salart) as salary from T_user Group by LVL;+------+-----------+| Lvl | Salary |+------+-----------+| A | 1100,4300 | | B | 1200 | | C | 1560 |+------+-----------+3 rowsinchSet (0.00 sec)
    • #group by + aggregate function
mysql> Select Lvl,group_concat (UID) as salary from T_user Group by LVL; +------+--------+| Lvl  | Salary |+------+--------+| A    | |    B    | 3      | | C    | 4 in       Set (0.00 sec) MySQL> select Lvl,count (UID) as salary from T_user Group by lvl;< /c10>+------+--------+| Lvl  | Salary |+------+--------+| A    |      2 | | B    |      1 | | C    |       in Set (0.00 sec)
    • #group by + have
Mysql> Select Lvl,group_concat (salart) from T_user GROUP by LVL have Group_concat (salart) =1200;+------+----------------------+| Lvl | Group_concat (Salart) |+------+----------------------+| B | |+------+----------------------+1 rowinchSet (0.00sec) MySQL> select Lvl,group_concat (salart) from T_user GROUP by LVL have Group_concat (salart) =1100;+------+----------------------+| Lvl | Group_concat (Salart) |+------+----------------------+| A | 1100,4300 |+------+----------------------+1 rowinchSet (0.00sec) MySQL>MySQL>Select Lvl,count (UID) as salary from T_user Group by LVL;+------+--------+| Lvl | Salary |+------+--------+|      A | 2 | |      B | 1 | |      C | 1 |+------+--------+3 rowsinchSet (0.00sec) MySQL> select Lvl,count (UID) as salary from T_user Group by LVL have count (UID) >1;+------+--------+| Lvl | Salary |+------+--------+|      A | 2 |+------+--------+1 rowinchSet (0.00 sec)

"MYSQL" Select from Group by

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.