CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: How to Quickly Create a Histogram in MySQL  (Read 325 times)

Evg

  • Junior Member
  • *
  • Posts: 11
  • Karma: +0/-0
    • agouti
How to Quickly Create a Histogram in MySQL
« on: 27 Jan 2022, 11:21:45 am »
I studied the ranking system, sorting on some sites: Reddit, Hacker News, Lobster and came across an article for 2011-08-16. I found her interesting.

Quote
This is a post about a super quick-and-dirty way to create a histogram in MySQL for numeric values.
There are multiple other ways to create histograms that are better and more flexible, using CASE statements and other types of complex logic. This method wins me over time and time again since it's just so easy to modify for each use case, and so short and concise.
This is how you do it:

Code: [Select]
SELECT ROUND(numeric_value, -2)    AS bucket,
       COUNT(*)                    AS COUNT,
       RPAD('', LN(COUNT(*)), '*') AS bar
FROM   my_table
GROUP  BY bucket;

http://blog.shlomoid.com/2011/08/how-to-quickly-create-histogram-in.html

I don't know if this is the right place to post it here. And I apologize for my English.

P.S. Your site, forum, articles are interesting, I read, I look. Thank you.
Interests: martial arts, sports, archeology, theology and programming

mmerlinn

  • Jr. Member
  • **
  • Posts: 71
  • Karma: +9/-0
  • Nutcake
Re: How to Quickly Create a Histogram in MySQL
« Reply #1 on: 29 Jan 2022, 12:51:51 am »
I don't know if this is the right place to post it here. And I apologize for my English.


Don't apologize for your English. Your English is orders of magnitude better than many whose only language is English.
The soul purr pus of a spell cheque cur is two valley date hour ignore ants.

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 849
  • Karma: +160/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: How to Quickly Create a Histogram in MySQL
« Reply #2 on: 29 Jan 2022, 01:17:14 am »
Your English is orders of magnitude better than many whose only language is English.
This. A thousand times this.
I'll fix every flaw, I'll break every law, I'll tear up the rulebook if that's what it takes. You will see, I will crush this cold machine.

 

SMF spam blocked by CleanTalk

Advertisement