I am in a SQL class and the teacher has asked us to update a value by 100 if the id number is even using the floor function.
I am not looking for someone to write the expresion, but someone to explain how the floor function could be used to do this.
Any help would be greatly appreciated.your lecturere probably wants to to divide your number by 2, get the floor() value and multiply it by 2 again to see if it is the same value
eg
7/2 = 3.5
floor(3.5) = 3
3 x 2 = 6
so we know 7 is not even
8/2 = 4
floor(4) = 4
4 x 2 = 8
so we know 8 is even|||Thanks a ton.
That was just the info i need to build my query. My brain must have been mush to not figure out that simple math.
just for FYI here is the query i cam up with, nothing complicated but with your help on the math i was able to come through.
UPDATE Salaries
SET Salary = Salary + 100
WHERE floor(empid / 2) * 2 = empid
UPDATE Salaries
SET Salary = Salary + 200
WHERE floor(empid / 2) * 2 != empid
Thanks again Matt, your a lifesaver!!!!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment