Skip to content

Instantly share code, notes, and snippets.

@napsternxg
Created June 13, 2014 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save napsternxg/01aa816277e55141406b to your computer and use it in GitHub Desktop.
Save napsternxg/01aa816277e55141406b to your computer and use it in GitHub Desktop.
SELECT ROUND(numeric_value, -2) AS bucket,
COUNT(*) AS COUNT,
RPAD('', LOG(COUNT(*)), '*') AS bar
FROM my_table
GROUP BY bucket;
/*
numeric_value = column name
-2 to round in steps of 100. Use -1 for steps of 10 and any positive vale for rounding to nearest decimal
LOG(COUNT(*)) is to make the count on log scale
Output:
+--------+----------+-----------------+
| bucket | count | bar |
+--------+----------+-----------------+
| -500 | 1 | |
| -400 | 2 | * |
| -300 | 2 | * |
| -200 | 9 | ** |
| -100 | 52 | **** |
| 0 | 5310766 | *************** |
| 100 | 20779 | ********** |
| 200 | 1865 | ******** |
| 300 | 527 | ****** |
| 400 | 170 | ***** |
| 500 | 79 | **** |
| 600 | 63 | **** |
| 700 | 35 | **** |
| 800 | 14 | *** |
| 900 | 15 | *** |
| 1000 | 6 | ** |
| 1100 | 7 | ** |
| 1200 | 8 | ** |
| 1300 | 5 | ** |
| 1400 | 2 | * |
| 1500 | 4 | * |
+--------+----------+-----------------+
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment