{"id":3337,"date":"2014-05-19T17:36:18","date_gmt":"2014-05-19T17:36:18","guid":{"rendered":"http:\/\/really.zonky.org\/?p=3337"},"modified":"2014-05-19T17:36:18","modified_gmt":"2014-05-19T17:36:18","slug":"mysql-bar-charts","status":"publish","type":"post","link":"https:\/\/really.zonky.org\/?p=3337","title":{"rendered":"MySQL: Bar Charts"},"content":{"rendered":"<p>So there I was, contemplating whether I could produce a nice and simple bar chart showing the number of films I&#8217;ve watched per month. Using just MySQL.<\/p>\n<p>\nI knew it was easy to produce a simple numerical count with <em>count(*)<\/em> and a <em>group by<\/em> clause, but a bar chart? Turns out it was easy with the <em>repeat<\/em> string function.<\/p>\n<pre>\r\nmysql&gt; select date_format(whence, \"%Y-%m\") \"Month\", \r\n          repeat('*', count(*)) \"Number of Films\" \r\n          from films group by date_format(whence, \"%Y-%m\");\r\n+---------+------------------------------------------------+\r\n| Month   | Number of Films                                |\r\n+---------+------------------------------------------------+\r\n| 2007-05 | ****                                           |\r\n| 2007-06 | ******                                         |\r\n| 2007-07 | ******                                         |\r\n| 2007-08 | *****                                          |\r\n| 2007-09 | ******                                         |\r\n| 2007-10 | ***                                            |\r\n| 2007-12 | ****                                           |\r\n| 2008-01 | *****                                          |\r\n| 2008-02 | ****                                           |\r\n| 2008-03 | *                                              |\r\n| 2008-04 | *****                                          |\r\n| 2008-05 | *****                                          |\r\n| 2008-06 | ******                                         |\r\n| 2008-07 | ****                                           |\r\n| 2008-08 | *****                                          |\r\n| 2008-09 | *****                                          |\r\n| 2008-10 | ****                                           |\r\n| 2008-11 | *****                                          |\r\n| 2008-12 | ***                                            |\r\n| 2009-01 | ***                                            |\r\n| 2009-03 | **                                             |\r\n| 2009-04 | ***                                            |\r\n| 2009-05 | **                                             |\r\n| 2009-06 | ****                                           |\r\n| 2009-07 | ****                                           |\r\n| 2009-08 | *                                              |\r\n| 2009-09 | **                                             |\r\n| 2009-10 | ****                                           |\r\n| 2009-11 | **                                             |\r\n| 2009-12 | **                                             |\r\n| 2010-01 | **********                                     |\r\n| 2010-02 | **********                                     |\r\n| 2010-03 | *************************                      |\r\n| 2010-04 | *****************************                  |\r\n| 2010-05 | ********************************************** |\r\n| 2010-06 | ***********************                        |\r\n| 2010-07 | ****************                               |\r\n| 2010-08 | **********                                     |\r\n| 2010-09 | ************                                   |\r\n| 2010-10 | **********                                     |\r\n| 2010-11 | ********                                       |\r\n| 2010-12 | *********                                      |\r\n| 2011-01 | *******************                            |\r\n| 2011-02 | *************                                  |\r\n| 2011-03 | **                                             |\r\n| 2011-04 | ************                                   |\r\n| 2011-05 | ********                                       |\r\n| 2011-06 | ***                                            |\r\n| 2011-07 | ****                                           |\r\n| 2011-08 | *********************                          |\r\n| 2011-09 | *                                              |\r\n| 2011-10 | **                                             |\r\n| 2011-11 | ***************                                |\r\n| 2011-12 | ********************                           |\r\n| 2012-01 | ********************                           |\r\n| 2012-02 | *******                                        |\r\n| 2012-03 | *******                                        |\r\n| 2012-04 | *****                                          |\r\n| 2012-05 | ******                                         |\r\n| 2012-06 | *******                                        |\r\n| 2012-07 | **************                                 |\r\n| 2012-08 | ************                                   |\r\n| 2012-09 | ***************                                |\r\n| 2012-10 | *******************                            |\r\n| 2012-11 | ****************                               |\r\n| 2012-12 | *******                                        |\r\n| 2013-01 | *************                                  |\r\n| 2013-02 | *************                                  |\r\n| 2013-03 | ******************                             |\r\n| 2013-04 | ******************                             |\r\n| 2013-05 | ********                                       |\r\n| 2013-06 | ************                                   |\r\n| 2013-07 | **************                                 |\r\n| 2013-08 | ***                                            |\r\n| 2013-09 | *************                                  |\r\n| 2013-10 | ********                                       |\r\n| 2013-11 | ***************                                |\r\n| 2013-12 | ***********************                        |\r\n| 2014-01 | *************************                      |\r\n| 2014-02 | ********                                       |\r\n| 2014-03 | *************                                  |\r\n| 2014-04 | ****************                               |\r\n| 2014-05 | ************                                   |\r\n+---------+------------------------------------------------+\r\n83 rows in set (0.02 sec)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So there I was, contemplating whether I could produce a nice and simple bar chart showing the number of films I&#8217;ve watched per month. Using just MySQL. I knew it was easy to produce a simple numerical count with count(*) and a group by clause, but a bar chart? Turns out it was easy with <a href='https:\/\/really.zonky.org\/?p=3337' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_share_on_mastodon":"0"},"categories":[226],"tags":[1201],"class_list":["post-3337","post","type-post","status-publish","format-standard","hentry","category-working-notes","tag-mysql","category-226-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1f2KI-RP","_links":{"self":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/3337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3337"}],"version-history":[{"count":3,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/3337\/revisions"}],"predecessor-version":[{"id":3340,"href":"https:\/\/really.zonky.org\/index.php?rest_route=\/wp\/v2\/posts\/3337\/revisions\/3340"}],"wp:attachment":[{"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/really.zonky.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}