Skip to content

Commit

Permalink
8.14 corrections and updates GG review
Browse files Browse the repository at this point in the history
Signed-off-by: Alkin Tezuysal <[email protected]>
  • Loading branch information
askdba committed Mar 7, 2022
1 parent ed00a41 commit 8cb370b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions recipes/tables/sibling.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ INSERT INTO sibling (name,birth) VALUES('Ilayda','2002-12-17');
INSERT INTO sibling (name,birth) VALUES('Lara','2009-06-03');

SELECT * FROM sibling;

# Age calculations

SELECT name,DATE_FORMAT(birth,'%Y-%m-%d') as dob
, DATE_FORMAT(NOW(),'%Y-%m-%d') as today
, TIMESTAMPDIFF( YEAR, birth, NOW() ) as age_years
, TIMESTAMPDIFF( MONTH, birth, NOW() ) % 12 as age_months
, FLOOR( TIMESTAMPDIFF( DAY, birth, now() ) % 30.4375 ) as age_days
FROM sibling;

SELECT name, birth, '2009-06-09' AS 'Lara\'s birth',
TIMESTAMPDIFF( YEAR, birth,'2009-06-09' ) as age_years,
TIMESTAMPDIFF( MONTH, birth,'2009-06-09' ) % 12 as age_months,
FLOOR( TIMESTAMPDIFF( DAY, birth,'2009-06-09' ) % 30.4375 ) as age_days
FROM sibling WHERE name <> 'Lara';

0 comments on commit 8cb370b

Please sign in to comment.