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
The web color picker function in this example use...
The image integration technology used by American...
Vue+iview menu and tab linkage I am currently dev...
In the nginx process model, tasks such as traffic...
Table of contents 1. What is scrapy_splash? 2. Th...
Problem Description When using Windows Server 201...
Preface When operating and managing Linux servers...
1. Basic Concepts 1. Sitemesh is a page decoratio...
Install axios and implement communication Here we...
Table of contents introduction Why bother? Commun...
How to solve the problem of being unable to acces...
Remount the data disk after initializing the syst...
What is a primary key? A primary key is a column ...
Preface The basic principle of MySQL master-slave...
Install zip decompression function under Linux Th...