- 论坛徽章:
- 93
|
- mysql> select * from tb1;
- +----+-------+
- | id | name |
- +----+-------+
- | 1 | aaaaa |
- | 2 | aaabb |
- | 3 | aabbc |
- | 4 | bbbbb |
- | 5 | ddddd |
- +----+-------+
- 5 rows in set
- mysql> select name, count(id), count(id) / (select count(*) as total from tb1) from tb1 as t group by name;
- +-------+-----------+-------------------------------------------------+
- | name | count(id) | count(id) / (select count(*) as total from tb1) |
- +-------+-----------+-------------------------------------------------+
- | aaaaa | 1 | 0.2000 |
- | aaabb | 1 | 0.2000 |
- | aabbc | 1 | 0.2000 |
- | bbbbb | 1 | 0.2000 |
- | ddddd | 1 | 0.2000 |
- +-------+-----------+-------------------------------------------------+
- 5 rows in set
- mysql> select name, count(id), count(id) / total from tb1, (select count(*) as total from tb1) as t group by name;
- +-------+-----------+-------------------+
- | name | count(id) | count(id) / total |
- +-------+-----------+-------------------+
- | aaaaa | 1 | 0.2000 |
- | aaabb | 1 | 0.2000 |
- | aabbc | 1 | 0.2000 |
- | bbbbb | 1 | 0.2000 |
- | ddddd | 1 | 0.2000 |
- +-------+-----------+-------------------+
- 5 rows in set
复制代码 |
|