Tuesday, October 6, 2009

A Pizza My Mind

I’m in a jolly mood today, so those of you looking for meaningful content in this blog post should just leave and come back next time. Nothing earth-shattering or enlightening this time… sorry… just something totally frivolous, meaningless, and tongue-in-cheek.

I’ll wait for those who want to go to take your leave… Go ahead… It's okay, I won't take it personally.

I'll wait…

Okay, for those of you who are left, let’s say that you have a business selling Pizza Baking Pans, and therefore you have a table with a Description, the Diameter (in inches), and the Height (in inches) of the pan:

create table #PizzaBakingPans
(
ID int identity(1,1) primary key
,Description varchar(20)
,Diameter numeric(4,2)
,Height numeric(4,2)
)
insert #PizzaBakingPans
select 'Traditional Personal', 8.0,0.5
union all select 'Traditional Small' ,10.0,0.5
union all select 'Traditional Medium' ,14.0,0.5
union all select 'Traditional Large' ,18.0,0.5
union all select 'Deep-Dish Small' ,10.0,3.5
union all select 'Deep-Dish Medium' ,14.0,3.5
union all select 'Deep-Dish Large' ,18.0,3.5
And let’s say your customers want to know the volume (in cubic inches) of these assorted pans.

Well, you may recall from your high school geometry class that the volume of a cylindrical object is defined as V = πr²h. So, with that in mind, you create the following SQL query:

select Description
,Volume=PI()*Z*Z*A
from #PizzaBakingPans
cross apply (select Z=Diameter/2
,A=Height) F
See? I told you I was going to be frivolous and tongue-in-cheek. Don’t say I didn’t warn you.

Even though it’s a key ingredient of pi*z*z*a, please refrain from throwing tomatoes at your screen. It's not my fault anyway. You can blame it on my daughter… she's the one who e-mailed me this joke.

Next time I promise I’ll have the usual challenging and mind-blowing content.

5 comments:

  1. Why do the cross apply? I'd just use the POWER() function:

    select Description, PI()*POWER((Diameter/2),2)*Height
    from #PizzaBakingPans

    ReplyDelete
  2. That daughter of yours sounds pretty weird! ;) haha and to the dude above me...I don't really know a lot about comp sci but I think the reason he didn't use the "easier" way was so he could make that AWESOME joke about pi*z*z*a...because it spells "pizza"...get it? Dude he said he was being frivolous...hop on the fun bus!

    ReplyDelete
  3. @Lindsay: Yeah, the word "weird" doesn't even begin to describe my daughter. Wink-wink. Thanks for setting Jon straight.

    @Jonathan: See Lindsay's message.

    ReplyDelete
  4. I missed the PI*Z*Z*A part in the solution. I get the joke now. I knew I should have left the room.....

    ReplyDelete
  5. @Jonathan: Believe me, I've done the same thing a million times. Sorry about Lindsay being so blunt... I have to teach her some restraint.

    ReplyDelete