Commit 2fb15239 authored by unknown's avatar unknown

manual.texi minor change log fixes

manual.texi	fix age calculations in the tutorial section to
manual.texi	determine age in integer years and to account for
manual.texi	relative order of dates within calendar year.


Docs/manual.texi:
  minor change log fixes
parent 9a4aac7e
...@@ -13170,75 +13170,89 @@ MySQL provides several functions that you can use to perform ...@@ -13170,75 +13170,89 @@ MySQL provides several functions that you can use to perform
calculations on dates, for example, to calculate ages or extract calculations on dates, for example, to calculate ages or extract
parts of dates. parts of dates.
To determine how many years old each of your pets is, compute age as the To determine how many years old each of your pets is, compute the
difference between the birth date and the current date. Do this by difference in the year part of the current date and the birth date, then
converting the two dates to days, take the difference, and divide by 365 (the subtract one if the current date occurs earlier in the calendar year than
number of days in a year): the birth date. The following query shows, for each pet, the birth date,
the current date, and the age in years.
@example
mysql> SELECT name, (TO_DAYS(NOW())-TO_DAYS(birth))/365 FROM pet; @example
+----------+-------------------------------------+ mysql> SELECT name, birth, CURRENT_DATE,
| name | (TO_DAYS(NOW())-TO_DAYS(birth))/365 | -> (YEAR(CURRENT_DATE)-YEAR(birth))
+----------+-------------------------------------+ -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
| Fluffy | 6.15 | -> AS age
| Claws | 5.04 | -> FROM pet;
| Buffy | 9.88 | +----------+------------+--------------+------+
| Fang | 8.59 | | name | birth | CURRENT_DATE | age |
| Bowser | 9.58 | +----------+------------+--------------+------+
| Chirpy | 0.55 | | Fluffy | 1993-02-04 | 2001-08-29 | 8 |
| Whistler | 1.30 | | Claws | 1994-03-17 | 2001-08-29 | 7 |
| Slim | 2.92 | | Buffy | 1989-05-13 | 2001-08-29 | 12 |
| Puffball | 0.00 | | Fang | 1990-08-27 | 2001-08-29 | 11 |
+----------+-------------------------------------+ | Bowser | 1989-08-31 | 2001-08-29 | 11 |
@end example | Chirpy | 1998-09-11 | 2001-08-29 | 2 |
| Whistler | 1997-12-09 | 2001-08-29 | 3 |
Although the query works, there are some things about it that could be | Slim | 1996-04-29 | 2001-08-29 | 5 |
improved. First, the result could be scanned more easily if the rows were | Puffball | 1999-03-30 | 2001-08-29 | 2 |
presented in some order. Second, the heading for the age column isn't very +----------+------------+--------------+------+
@end example
Here, @code{YEAR()} pulls out the year part of a date and @code{RIGHT()}
pulls off the rightmost five characters that represent the @code{MM-DD}
(calendar year) part of the date. The part of the expression that
compares the @code{MM-DD} values evaluates to 1 or 0, which adjusts the
year difference down a year if @code{CURRENT_DATE} occurs earlier in
the year than @code{birth}. The full expression is somewhat ungainly,
so an alias (@code{age}) is used to make the output column label more
meaningful. meaningful.
The first problem can be handled by adding an @code{ORDER BY name} clause to The query works, but the result could be scanned more easily if the rows
sort the output by name. To deal with the column heading, provide a name for were presented in some order. This can be done by adding an @code{ORDER
the column so that a different label appears in the output (this is called a BY name} clause to sort the output by name:
column alias):
@example @example
mysql> SELECT name, (TO_DAYS(NOW())-TO_DAYS(birth))/365 AS age mysql> SELECT name, birth, CURRENT_DATE,
-> (YEAR(CURRENT_DATE)-YEAR(birth))
-> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
-> AS age
-> FROM pet ORDER BY name; -> FROM pet ORDER BY name;
+----------+------+ +----------+------------+--------------+------+
| name | age | | name | birth | CURRENT_DATE | age |
+----------+------+ +----------+------------+--------------+------+
| Bowser | 9.58 | | Bowser | 1989-08-31 | 2001-08-29 | 11 |
| Buffy | 9.88 | | Buffy | 1989-05-13 | 2001-08-29 | 12 |
| Chirpy | 0.55 | | Chirpy | 1998-09-11 | 2001-08-29 | 2 |
| Claws | 5.04 | | Claws | 1994-03-17 | 2001-08-29 | 7 |
| Fang | 8.59 | | Fang | 1990-08-27 | 2001-08-29 | 11 |
| Fluffy | 6.15 | | Fluffy | 1993-02-04 | 2001-08-29 | 8 |
| Puffball | 0.00 | | Puffball | 1999-03-30 | 2001-08-29 | 2 |
| Slim | 2.92 | | Slim | 1996-04-29 | 2001-08-29 | 5 |
| Whistler | 1.30 | | Whistler | 1997-12-09 | 2001-08-29 | 3 |
+----------+------+ +----------+------------+--------------+------+
@end example @end example
To sort the output by @code{age} rather than @code{name}, just use a To sort the output by @code{age} rather than @code{name}, just use a
different @code{ORDER BY} clause: different @code{ORDER BY} clause:
@example @example
mysql> SELECT name, (TO_DAYS(NOW())-TO_DAYS(birth))/365 AS age mysql> SELECT name, birth, CURRENT_DATE,
-> FROM pet ORDER BY age; -> (YEAR(CURRENT_DATE)-YEAR(birth))
+----------+------+ -> - (RIGHT(CURRENT_DATE,5)<RIGHT(birth,5))
| name | age | -> AS age
+----------+------+ -> FROM pet ORDER BY age;
| Puffball | 0.00 | +----------+------------+--------------+------+
| Chirpy | 0.55 | | name | birth | CURRENT_DATE | age |
| Whistler | 1.30 | +----------+------------+--------------+------+
| Slim | 2.92 | | Chirpy | 1998-09-11 | 2001-08-29 | 2 |
| Claws | 5.04 | | Puffball | 1999-03-30 | 2001-08-29 | 2 |
| Fluffy | 6.15 | | Whistler | 1997-12-09 | 2001-08-29 | 3 |
| Fang | 8.59 | | Slim | 1996-04-29 | 2001-08-29 | 5 |
| Bowser | 9.58 | | Claws | 1994-03-17 | 2001-08-29 | 7 |
| Buffy | 9.88 | | Fluffy | 1993-02-04 | 2001-08-29 | 8 |
+----------+------+ | Fang | 1990-08-27 | 2001-08-29 | 11 |
| Bowser | 1989-08-31 | 2001-08-29 | 11 |
| Buffy | 1989-05-13 | 2001-08-29 | 12 |
+----------+------------+--------------+------+
@end example @end example
A similar query can be used to determine age at death for animals that have A similar query can be used to determine age at death for animals that have
...@@ -13248,12 +13262,14 @@ values, compute the difference between the @code{death} and @code{birth} ...@@ -13248,12 +13262,14 @@ values, compute the difference between the @code{death} and @code{birth}
values: values:
@example @example
mysql> SELECT name, birth, death, (TO_DAYS(death)-TO_DAYS(birth))/365 AS age mysql> SELECT name, birth, death,
-> FROM pet WHERE death IS NOT NULL ORDER BY age; -> (YEAR(death)-YEAR(birth)) - (RIGHT(death,5)<RIGHT(birth,5))
-> AS age
-> FROM pet WHERE death IS NOT NULL ORDER BY age;
+--------+------------+------------+------+ +--------+------------+------------+------+
| name | birth | death | age | | name | birth | death | age |
+--------+------------+------------+------+ +--------+------------+------------+------+
| Bowser | 1989-08-31 | 1995-07-29 | 5.91 | | Bowser | 1989-08-31 | 1995-07-29 | 5 |
+--------+------------+------------+------+ +--------+------------+------------+------+
@end example @end example
...@@ -13328,7 +13344,7 @@ mysql> SELECT name, birth FROM pet ...@@ -13328,7 +13344,7 @@ mysql> SELECT name, birth FROM pet
Note that @code{MONTH} returns a number between 1 and 12. And Note that @code{MONTH} returns a number between 1 and 12. And
@code{MOD(something,12)} returns a number between 0 and 11. So the @code{MOD(something,12)} returns a number between 0 and 11. So the
addition has to be after the @code{MOD()} otherwise we would go from addition has to be after the @code{MOD()}, otherwise we would go from
November (11) to January (1). November (11) to January (1).
...@@ -46696,35 +46712,35 @@ not yet 100% confident in this code. ...@@ -46696,35 +46712,35 @@ not yet 100% confident in this code.
@appendixsubsec Changes in release 3.23.42 @appendixsubsec Changes in release 3.23.42
@itemize @bullet @itemize @bullet
@item @item
Enforce that all tables in a @code{MERGE} table comes from the same Enforce that all tables in a @code{MERGE} table come from the same
database. database.
@item @item
Fixed bug with @code{LOAD DATA INFILE} and transactional tables. Fixed bug with @code{LOAD DATA INFILE} and transactional tables.
@item @item
Fix bug when using @code{INSERT DELAYED} with wrong column definition. Fix bug when using @code{INSERT DELAYED} with wrong column definition.
@item @item
Fixed coredump during REPAIR of some particulary broken tables. Fixed coredump during @code{REPAIR} of some particularly broken tables.
@item @item
Fixed bug in @code{InnoDB} and @code{AUTO_INCREMENT} columns. Fixed bug in @code{InnoDB} and @code{AUTO_INCREMENT} columns.
@item @item
Fixed critical bug in @code{InnoDB} and @code{BLOB}'s. If one has used Fixed critical bug in @code{InnoDB} and @code{BLOB} columns. If one has
@code{BLOB}'s larger than 8K in an @code{InnoDB} table one must dump used @code{BLOB} columns larger than 8K in an @code{InnoDB} table, one must
the table with @code{mysqldump}, drop it and restore it from the dump. dump the table with @code{mysqldump}, drop it and restore it from the dump.
@item @item
Applied large patch for OS/2 from Yuri Dario. Applied large patch for OS/2 from Yuri Dario.
@item @item
Fixed problem with InnoDB when one could get the error @code{Can't Fixed problem with @code{InnoDB} when one could get the error @code{Can't
execute the given command...} even when one didn't have an active execute the given command...} even when one didn't have an active
transaction. transaction.
@item @item
Applied some minor fixes that concerns Gemini. Applied some minor fixes that concern Gemini.
@item @item
Use real arithmetic operations even in integer context if not Use real arithmetic operations even in integer context if not
all arguments are integers. (Fixes uncommon bug in some integer all arguments are integers. (Fixes uncommon bug in some integer
context). contexts).
@item @item
Don't force everything to lower cases on windows. (To fix problem Don't force everything to lower cases on Windows. (To fix problem
with windows and @code{ALTER TABLE}). Now @code{--lower_case_names} with Windows and @code{ALTER TABLE}). Now @code{--lower_case_names}
also works on Unix. also works on Unix.
@item @item
Fixed that automatic rollback that is done when thread end doesn't lock Fixed that automatic rollback that is done when thread end doesn't lock
...@@ -46740,7 +46756,7 @@ Added option @code{--sql-mode=option[,option[,option]]}. ...@@ -46740,7 +46756,7 @@ Added option @code{--sql-mode=option[,option[,option]]}.
@xref{Command-line options}. @xref{Command-line options}.
@item @item
Fixed possible problem with @code{shutdown} on Solaris where the Fixed possible problem with @code{shutdown} on Solaris where the
@code{.pid} file wasn't deleted. @file{.pid} file wasn't deleted.
@item @item
InnoDB now supports < 4 GB rows. The former limit was 8000 bytes. InnoDB now supports < 4 GB rows. The former limit was 8000 bytes.
@item @item
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment