Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

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)

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)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!