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 -
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