mysql> select * from t1;
+--------+
| deptno |
+--------+
| 10 |
| 10 |
| 10 |
| 20 |
| 20 |
| 20 |
| 20 |
| 30 |
| 30 |
| 30 |
| 30 |
| 30 |
| 30 |
+--------+
13 rows in set (0.00 sec)
1. 水平直方图 返回结果集如下所示,*号个数为对应DEPTNO的记录数。
DEPTNO CNT
------ ----------
10 ***
20 *****
30 ******
查询:
mysql> select deptno,lpad('*',count(*),'*') cnt from t1 group by deptno;
+--------+--------+
| deptno | cnt |
+--------+--------+
| 10 | *** |
| 20 | **** |
| 30 | ****** |
+--------+--------+
3 rows in set (0.00 sec)
2. 垂直直方图 返回结果集如下所示,*号个数为对应DEPTNO的记录数。
D10 D20 D30
--- --- ---
*
* *
* *
* * *
* * *
* * *
查询:
mysql> select max(d10) d10,max(d20) d20,max(d30) d30 from
-> (select row_number() over (partition by deptno) rn,
-> case when deptno=10 then '*' else '' end d10,
-> case when deptno=20 then '*' else '' end d20,
-> case when deptno=30 then '*' else '' end d30
-> from t1) t group by rn;
+------+------+------+
| d10 | d20 | d30 |
+------+------+------+
| * | * | * |
| * | * | * |
| * | * | * |
| | * | * |
| | | * |
| | | * |
+------+------+------+
6 rows in set (0.00 sec)
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有