I had 2 250 gig Hitachi drives that were showing up in my BIOS and operating system as 33.8 gigabytes. A while back certain operating systems had a 32gig limit on the drive size that would be recognized by the operating system. To support this, drives were shipped with jumpers to allow them to be "clipped" at 32 gigs.
Looking at this objectively, it seems like a really silly thing to do. Why spend the extra money to buy a drive that you are going to clip back to 32 gigs. Also, I don't recall EVER having an operating system that couldn't support more than 32 gigs. The fact that it wasn't an issue back in 1999 when I purchased my first >32 gig drive (40 to be exact), I don't see why 9 years later drives are still being shipped with this fairly terrible hack. This is mostly justifying my lack of attention to the different jumper settings on the drive. It just seems pretty amazing that after working with computers heavily since 1994, this is the first time I've ever run across this problem.
Wednesday, March 26, 2008
Tuesday, March 18, 2008
SQL Counting Multiple Columns With Criteria
When doing counts, sometimes you want to count a record only when it meets a certain criteria. This can be annoying because the criteria generally needs to be posted in the "where" clause. This will give you only one count per sql query. If you want to have multiple counts per sql query you need to do sub-queries that can be costly.
select (Select count(FavoriteCandy) from mytable where FavoriteCandy='Tootsie Rolls') as TootsieCount, (Select count(FavoriteCandy) from mytable where FavoriteCandy='Baby Ruth') as BabyRuthCount
While this works it is really expensive. If multiple different counts over a large number of records is required, this method is not appropriate. While parusing the vast internets I ran into a different way of accomplishing the same task. I much prefer it to the former method.
select SUM(CASE when FavoriteCandy='Tootsie Rolls' THEN 1 END) as TootsieCount,SUM(CASE when FavoriteCandy='Baby Ruth' THEN 1 END) as BabyRuthCount from mytable
This treats the successful records as the number one and then sums the number of successes. When trying to count a number of different columns with criteria, this is definitly a cleaner and faster way to make the magic happen.
select (Select count(FavoriteCandy) from mytable where FavoriteCandy='Tootsie Rolls') as TootsieCount, (Select count(FavoriteCandy) from mytable where FavoriteCandy='Baby Ruth') as BabyRuthCount
While this works it is really expensive. If multiple different counts over a large number of records is required, this method is not appropriate. While parusing the vast internets I ran into a different way of accomplishing the same task. I much prefer it to the former method.
select SUM(CASE when FavoriteCandy='Tootsie Rolls' THEN 1 END) as TootsieCount,SUM(CASE when FavoriteCandy='Baby Ruth' THEN 1 END) as BabyRuthCount from mytable
This treats the successful records as the number one and then sums the number of successes. When trying to count a number of different columns with criteria, this is definitly a cleaner and faster way to make the magic happen.
Subscribe to:
Posts (Atom)