Beginning SQL

Beginning SQL Beginning SQL

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

You can raise a number to any power, from 1 to whatever the database system can handle; some huge numbers, however, will be too large for the database system to handle. For example, if you want to know what the results are when the MemberId is squared (raised to the power of 2), cubed (raised to the power of 3), and raised to the power of 7, you’d write the following SQL SELECT MemberId, POWER(MemberId,2), POWER(MemberId, 3) , POWER(MemberId, 7) FROM MemberDetails ORDER BY MemberId; Executing the statement gives the results in the following table: Manipulating Data MemberId POWER(MemberId,2) POWER(MemberId, 3) POWER(MemberId, 7) 1 1 1 1 4 16 64 16384 5 25 125 78125 6 36 216 279936 7 49 343 823543 8 64 512 2097152 9 81 729 4782969 10 100 1000 10000000 11 121 1331 19487171 12 144 1728 35831808 13 169 2197 62748517 14 196 2744 105413504 15 225 3375 170859375 For the first and second rows in the preceding table, the columns were calculated as shown in the following table: MemberId POWER(MemberId,2) POWER(MemberId, 3) POWER(MemberId, 7) 1 1 * 1 = 1 1 * 1 * 1 = 1 1 * 1 * 1 * 1 * 1 * 1 * 1 = 1 4 4 * 4 = 16 4 * 4 * 4 = 64 4 * 4 * 4 * 4 * 4 * 4 * 4 = 16384 Now that you’ve learned how to raise to the power of 2, you can put that in reverse and find the square root of a number. 161

You can raise a number to any power, from 1 to whatever the database system can handle; some huge<br />

numbers, however, will be too large for the database system to handle. For example, if you want to<br />

know what the results are when the MemberId is squared (raised to the power of 2), cubed (raised to the<br />

power of 3), and raised to the power of 7, you’d write the following <strong>SQL</strong><br />

SELECT MemberId, POWER(MemberId,2), POWER(MemberId, 3) , POWER(MemberId, 7)<br />

FROM MemberDetails<br />

ORDER BY MemberId;<br />

Executing the statement gives the results in the following table:<br />

Manipulating Data<br />

MemberId POWER(MemberId,2) POWER(MemberId, 3) POWER(MemberId, 7)<br />

1 1 1 1<br />

4 16 64 16384<br />

5 25 125 78125<br />

6 36 216 279936<br />

7 49 343 823543<br />

8 64 512 2097152<br />

9 81 729 4782969<br />

10 100 1000 10000000<br />

11 121 1331 19487171<br />

12 144 1728 35831808<br />

13 169 2197 62748517<br />

14 196 2744 105413504<br />

15 225 3375 170859375<br />

For the first and second rows in the preceding table, the columns were calculated as shown in the following<br />

table:<br />

MemberId POWER(MemberId,2) POWER(MemberId, 3) POWER(MemberId, 7)<br />

1 1 * 1 = 1 1 * 1 * 1 = 1 1 * 1 * 1 * 1 * 1 * 1 * 1 = 1<br />

4 4 * 4 = 16 4 * 4 * 4 = 64 4 * 4 * 4 * 4 * 4 * 4 * 4 = 16384<br />

Now that you’ve learned how to raise to the power of 2, you can put that in reverse and find the square<br />

root of a number.<br />

161

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

Saved successfully!

Ooh no, something went wrong!