20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5<br />

The FLOOR() Function<br />

The FLOOR() function works in the opposite way as CEILING() in that it rounds down to the next lowest<br />

integer value. For example, 3.35 would be rounded down to 3, 5.99 rounded down to 5, and -3.35<br />

rounded down to -4, as -4 is lower than -3. Again, the FLOOR() function is not supported by MS Access’s<br />

version of <strong>SQL</strong>.<br />

The following is the basic syntax for the FLOOR() function:<br />

FLOOR(number_to_be_floored)<br />

Rewrite the <strong>SQL</strong> used in the previous section and replace CEILING() with FLOOR():<br />

SELECT DVDPrice, FLOOR(DVDPrice)<br />

FROM Films<br />

ORDER BY DVDPrice;<br />

Running the <strong>SQL</strong> provides the results shown in the following table:<br />

DVDPrice FLOOR(DVDPrice)<br />

NULL NULL<br />

NULL NULL<br />

NULL NULL<br />

NULL NULL<br />

NULL NULL<br />

2.99 2<br />

8.95 8<br />

8.95 8<br />

9.99 9<br />

9.99 9<br />

12.99 12<br />

12.99 12<br />

12.99 12<br />

12.99 12<br />

15.99 15<br />

This time, the FLOOR() function has removed the decimal point but reduced the number to the next lowest<br />

integer; so 2.99 becomes 2, whereas with CEILING() it would become 3.<br />

The ROUND() Function<br />

The last of the rounding functions rounds in a more traditional way: to the nearest whole-number value.<br />

Rather than always rounding up like CEILING() or down like FLOOR(), the ROUND() function rounds<br />

166

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

Saved successfully!

Ooh no, something went wrong!