Andrew T. Weber

Posts from September 2011

Beautiful Morning

Sep 20
08:49
I'm feeling pretty grateful this morning that I can wake up to views like this :)

Holy Name Cathedral in downtown Chicago
Holy Name Cathedral in downtown Chicago

Avoid dividing by zero in MySQL

Tags › MySQL
Sep 11
20:41
Typically, when you try to divide by zero in MySQL, the result will be NULL. In certain cases, however, you'd like the result to be the numerator.

For example, when posts are receiving votes, we want a post with 8 yes votes and 0 no votes to have a ratio of 8 not of NULL. The cheap solution is to add +1 to both the yes and no votes, but then the ratio will be slightly inaccurate (9 in this case). The solution is to use MySQL CASE.

SELECT `posts`.`id`, 
    (CASE `vote_no`
        WHEN 0 THEN `vote_yes`
        ELSE (`vote_yes`/`vote_no`)
    END) AS `vote_ratio`
FROM `posts`

New Color Scheme

Tags › Cars, Website
Sep 9
16:22
I updated my website again. Keeping the same layout, but with a black header and blue body. The old style was too bland. Hope you like it :) I'm adding my own smileys too.

To make this post a little more interesting, here's a snapshot of a video I took of "Eleanor" from Gone in 60 Seconds driving down Chicago Ave.

1967 Shelby GT500E
1967 Shelby GT500E

MYSQL Group by date based on timestamp

Tags › MySQL
Sep 8
11:47
If you have a table in MySQL with a Unix timestamp column (int 11) and you'd like to group results by date, you can run this simple query.

SELECT
    COUNT(`id`) AS `total`,
    DATE(FROM_UNIXTIME(`my_timestamp`)) AS `my_date`
FROM `my_table`
GROUP BY `my_date` DESC


If you want to group by month and year, ignoring the date, you can modify the query like this:

SELECT
    COUNT(`id`) AS `total`,
    MONTH(FROM_UNIXTIME(`my_timestamp`)) AS `my_month`,
    YEAR(FROM_UNIXTIME(`my_timestamp`)) AS `my_year`,
FROM `my_table`
GROUP BY `my_year`, `my_month` DESC

Eminem on Piano

Tags › Music, News
Sep 7
15:25
I recently downloaded the trial version of Finale Notepad. Most of the music I write / transcribe is going to be for piano, so I don't really need the full version.

One of the first things I transcribed is "Cleanin' Out my Closet" by Eminem. You can download the sheet music here:

Cleanin' Out my Closet piano sheet music

It's probably not perfect, but I've only heard the song three or four times, and hopefully you'd be playing with some variation if you actually performed it.

Coming soon: a live recording of the song featuring Eshy F Baby on vocals! :)

Archives

2013 (2)
February (2)
2012 (2)
April (1)
January (1)
2011 (22)

Andrew T. Weber Blog RSS

Tags

Boston (2)
Cars (9)
Chicago (5)
jQuery (1)
Music (2)
MySQL (2)
News (9)
Photography (6)
Travel (3)
Website (5)