Beginning SQL
Beginning SQL Beginning SQL
Chapter 5 Consider the following SQL query: SELECT MemberId, MemberId - 10, ABS(MemberId - 10) FROM MemberDetails; Executing the query provides the results shown in the following table: MemberId MemberId - 10 ABS(MemberId - 10) 1 -9 9 4 -6 6 5 -5 5 6 -4 4 7 -3 3 8 -2 2 9 -1 1 10 0 0 11 1 1 12 2 2 13 3 3 14 4 4 15 5 5 Look at the first row in the preceding table (remember that the order of your results may well be different). The way the equation is worked out for the second column is as follows: MemberId – 10 = 1 – 10 = -0. Results for the third column are worked out as shown here: ABS(MemberId – 10) = ABS(1 – 10) = ABS(-9) = 9. In the third column, the negative result has its sign removed, and therefore -9 becomes simply 9. The POWER() Function 160 The POWER() function is an exponential function that raises a number by the power of a second number. For example, it could be used to find the square of a number — a number multiplied by itself. The function takes two parameters. The first is the expression to be raised to a power, and the second is the power to which it is raised. The basic syntax is as follows: POWER(expression, power_raise_to)
- Page 308: Chapter 4 134 Drop the MoreHolidayB
- Page 312: Chapter 4 136 If you want to return
- Page 316: Chapter 4 If you’re using IBM DB2
- Page 320: Chapter 4 140 index helps speed up
- Page 324: Chapter 4 142 The results you get m
- Page 328: Chapter 4 144 The results of the qu
- Page 332: Chapter 4 146 Remember, IBM DB2 doe
- Page 336: Chapter 4 148 UPDATE Films SET Film
- Page 340: Chapter 4 150 Finally, you do the s
- Page 344: Chapter 4 152 SELECT * FROM MemberD
- Page 348: Chapter 4 ❑ Choose meaningful nam
- Page 354: 5 Manipulating Data In Chapter 3, y
- Page 358: The results of this query are as fo
- Page 364: Chapter 5 The SQRT() Function The S
- Page 368: Chapter 5 164 chairperson now also
- Page 372: Chapter 5 The FLOOR() Function The
- Page 376: Chapter 5 DVDPrice ROUND(DVDPrice,1
- Page 380: Chapter 5 Note that, as with all th
- Page 384: Chapter 5 The TRIM() Functions Trim
- Page 388: Chapter 5 174 In Oracle and IBM’s
- Page 392: Chapter 5 176 FirstName SOUNDEX(Fir
- Page 396: Chapter 5 Date Functions 178 Someti
- Page 400: Chapter 5 The syntax for the CAST()
- Page 404: Chapter 5 NULLs and Strings 182 NUL
- Page 408: Chapter 5 184 SELECT FirstName, Las
Chapter 5<br />
Consider the following <strong>SQL</strong> query:<br />
SELECT MemberId, MemberId - 10, ABS(MemberId - 10)<br />
FROM MemberDetails;<br />
Executing the query provides the results shown in the following table:<br />
MemberId MemberId - 10 ABS(MemberId - 10)<br />
1 -9 9<br />
4 -6 6<br />
5 -5 5<br />
6 -4 4<br />
7 -3 3<br />
8 -2 2<br />
9 -1 1<br />
10 0 0<br />
11 1 1<br />
12 2 2<br />
13 3 3<br />
14 4 4<br />
15 5 5<br />
Look at the first row in the preceding table (remember that the order of your results may well be different).<br />
The way the equation is worked out for the second column is as follows: MemberId – 10 = 1 –<br />
10 = -0.<br />
Results for the third column are worked out as shown here: ABS(MemberId – 10) = ABS(1 – 10) =<br />
ABS(-9) = 9.<br />
In the third column, the negative result has its sign removed, and therefore -9 becomes simply 9.<br />
The POWER() Function<br />
160<br />
The POWER() function is an exponential function that raises a number by the power of a second number.<br />
For example, it could be used to find the square of a number — a number multiplied by itself. The function<br />
takes two parameters. The first is the expression to be raised to a power, and the second is the<br />
power to which it is raised. The basic syntax is as follows:<br />
POWER(expression, power_raise_to)