赞
踩
需求:统计当前数据库user_tasks表中,不同status字段值对应的记录条数及占比
- SELECT
- `status`,
- number,
- concat(round(number / total * 100.00, 2), '%') percent
- FROM
- (
- SELECT
- *
- FROM
- (
- SELECT
- `status`,
- COUNT(1) number
- FROM
- `user_tasks`
- GROUP BY
- `status`
- ) t1
- INNER JOIN(
- SELECT
- COUNT(1) total
- FROM
- `user_tasks`
- ) t2 ON 1 = 1
- ) t
解析:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。