PrefaceHistogram is a basic statistical information provided by RDBMS. Its most typical use is to estimate the selectivity of query predicates in order to select an optimized query execution plan. Common types of histograms include: equal-width histogram, equal-height histogram, V-optimized histogram, MaxDiff histogram, etc. Note: The test database version is MySQL 8.0 If you need to create tables and enter data under user scott, you can refer to: Scott creates tables and enters data SQL script 1. DemandUse SQL to generate a horizontally extending histogram. For example, a horizontal histogram is used to display the number of volunteers in each department, with an asterisk "*" representing an employee. The returned result set should be like:
2. SolutionUse group by to group, find the total number, and then fill it with lpad select deptno, lpad('*',count(*),'*') as cnt from emp group by deptno; Testing Log: mysql> select deptno, -> lpad('*',count(*),'*') as cnt -> from emp -> group by deptno; +--------+--------+ | deptno | cnt | +--------+--------+ | 10 | *** | | 20 | ***** | | 30 | ****** | +--------+--------+ 3 rows in set (0.00 sec) SummarizeThis is the end of this article about creating a horizontal histogram in MySQL. For more relevant content about creating a horizontal histogram in MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! |
<<: Convert XHTML CSS pages to printer pages
>>: The whole process of configuring reverse proxy locally through nginx
"Page screenshot" is a requirement ofte...
Online Preview https://jsrun.pro/AafKp/ First loo...
Table of contents 1. Component Registration 1.1 G...
Preface I wrote an article about rem adaptation b...
This article shares the specific code of JS to ac...
chmod Command Syntax This is the correct syntax w...
Introduction In a production environment, in orde...
With the right settings, you can force Linux user...
During my internship in my senior year, I encount...
The DATE_ADD() function adds a specified time int...
How to install flash in Linux 1. Visit the flash ...
lsof (list open files) is a tool to view files op...
There are two tables, and the records in table A ...
Copy code The code is as follows: @charset "...
Table of contents Overview How to achieve it Spec...