My Blog

Welcome! What is this blog for/What will be blogged here? Well, frankly, only time will tell that ... ;-) The plan is to have stuff like ... what I plan to do/Interesting things that I want to share. My interests and hobbies ... and what I'm doing/not doing for it. Random thoughts/Opinions. Just about anything I feel like writing! have fun!

Thursday, October 14, 2004

SQL queries using sign()

Mike Chirico writes an interesting way in which we can compare two numbers using the abs and sign functions. At first you would think that he's just playing with them for fun ... at the end of the blog entry he uses it in a SQL query - that was neat!

check it out!

To spoil the fun a bit, the SQL looks like this -
select name,                                                                                        

sum(score*(1-abs(sign(exam-1)))) as exam1,
sum(score*(1-abs(sign(exam-2)))) as exam2,
sum(score*(1-abs(sign(exam-3)))) as exam3,
sum(score*(1-abs(sign(exam-4)))) as exam4
from exams group by name;

0 Comments:

Post a Comment

<< Home