Archive for October, 2009
-
Blackberry’s Days as the Fruitiest Phone Are Numbered
As Tyler Durden once said, on a long enough timeline the survival rate for everyone drops to zero. He was talking about the Blackberry.
If these numbers are to be believed, Apple is totally killing it in gaining smartphone market share. In a few short years they have reached 30% of the smartphone market compared to BB’s 40%. You know the Blackberry is going down over the long term.
Having owned both phones, I must say I really liked the Blackberry when I had one, but the iPhone is simply awesome (although in fairness I haven’t touched an updated BB model – the last time I touched one was two years ago). It’s the apps, baby. One thing I can say in positive terms about the BB is that although I’ve gotten used to the iPhone’s touch-only keyboard and can blast out an email in short order, I think I was still slightly faster on the BB.
AAPL just took a massive hit today, so it’s going to be time to get back in soon before they unleash the iPhone in China.
-
Highwinds Described as “Internet Superpower”
Some say there’s a new cold war brewing; data centers are cold, after all. Not to worry – Highwinds is already working on cyberdecks, so we’ll be ready to save the world when the time comes.
-
Calculating the Differences Between Consecutive Rows with SQL
Just a quickie. I’m sure this is obvious to the seasoned SQL freaks out there, but it was a new solution for me.
We were recently trying to figure out a simple query to generate a set of differences in values between sets of consecutive rows in a database table. Basically, the table is full of timestamp snapshots with associated values, and we need to calculate the differences between the values in each snapshot for a time period.
The simple solution I came up with is to normalize the dates, and then use them as a join criteria with a virtual table and some simple date math. You treat the original unmodified table as one side of the join, and a virtual select of the same table with some date math applied to the normalized dates as the other side of the join. So, for tables with timestamps five seconds apart, you simply pull the date back by five seconds on the virtual table and join the dates together. You end up with a single row joining each row with its previous peer, and you can then do direct math within the row to calculate the differences in values.
Here’s a simple MySQL script that demonstrates the technique, which will probably make more sense than my explanation.
CREATE TABLE consecutiveDates ( id INT NOT NULL AUTO_INCREMENT, valueDate TIMESTAMP NOT NULL, value NUMERIC(10) NOT NULL, PRIMARY KEY (id) ) INSERT INTO consecutiveDates VALUES (NULL, TIMESTAMP('2009-08-01 10:00:00'), 10); INSERT INTO consecutiveDates VALUES (NULL, TIMESTAMP('2009-08-01 10:00:05'), 25); INSERT INTO consecutiveDates VALUES (NULL, TIMESTAMP('2009-08-01 10:00:10'), 50); SELECT actual.*, virtual.*, IFNULL((virtual.virtualValue - actual.value), 0) AS 'difference' FROM consecutiveDates actual LEFT OUTER JOIN ( SELECT id AS 'virtualId', valueDate AS 'actualVirtualDate', value AS 'virtualValue', TIMESTAMPADD(SECOND, -5, valueDate) AS 'adjustedVirtualDate' FROM consecutiveDates ) virtual ON virtual.adjustedVirtualDate = actual.valueDate
If you have dates that don’t line up perfectly like my example, you can use basic date math/conversion to normalize the dates in each row in to a rounded representation (i.e. nearest five seconds, nearest minute, etc.). With basic SQL grouping, you can then easily smash together rows that are close enough to each other to be combined in to a single row and achieve the same effect as shown in the script.
This technique is obviously not limited to dates; you can use a similar approach with virtual row IDs in MySQL. By creating an integer session variable representing a row ID, and then selecting/incrementing it with each row in the query, you can apply basic math to the virtual table’s select statement to offset the session variable by -1 and use that as the join criteria.
Tagged Yelling
Most Popular Yelling
- Scrolling Large Data Sets in Flex Charts (31)
- How To Become A Software Engineer/Programmer (15)
- On A Personal Note (10)
- Abandoning ColdFusion? (9)
- Adobe Says: "Thousands of Developers are using CF 8" (9)
- What to do about Healthcare? (8)
- CFUNITED Day 2 (7)
- Build Tools: Maven Flex Plugins (7)
- Why People Hate Vista (and Other Microsoft Products) (7)
- Opinions on JDeveloper, Oracle's J2EE Strategy (6)
Stuff I Like
More Yelling
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- January 2007
- December 2006
- August 2006
- July 2006
- June 2006
- April 2006
- February 2006
- December 2005
- November 2005
- October 2005
- August 2005
- July 2005
- June 2005