Puzzle 2017-02-29 Median


— Sample data for Question

DECLARE @datetable TABLE (personid INT IDENTITY(1,1) NOT NULL PRIMARY KEY, PersonName NVARCHAR(255), Birthdate DATETIME)
— insert values into the table variable
INSERT INTO @datetable (PersonName, Birthdate)
VALUES(‘John Doe’,’19801001′)

INSERT INTO @datetable (PersonName, Birthdate)
VALUES(‘Jane Smith’,’19810501′)

INSERT INTO @datetable (PersonName, Birthdate)
VALUES(‘Kate Jones’,’19790906′)

INSERT INTO @datetable (PersonName, Birthdate)
VALUES(‘Philip Michaels’,’19820811′)

INSERT INTO @datetable (PersonName, Birthdate)
VALUES(‘Kelly McAnn’,’19780821′)

— Sample data for Bonus Question

CREATE TABLE [dbo].[presidents](
[President] [nvarchar](255) NULL,
[BirthDate] [nvarchar](255) NULL,
[TermStart] [nvarchar](255) NULL,
[TermEnd] [nvarchar](255) NULL
) ON [PRIMARY]

GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’George Washington’, N’February 22, 1732′, N’April 30, 1789′, N’ March 4, 1797′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’John Adams’, N’October 30, 1735′, N’March 4, 1797 ‘, N’ March 4, 1801′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Thomas Jefferson’, N’April 13, 1743′, N’March 4, 1801 ‘, N’ March 4, 1809′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’James Madison’, N’March 16, 1751′, N’March 4, 1809 ‘, N’ March 4, 1817′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’James Monroe’, N’April 28, 1758′, N’March 4, 1817 ‘, N’ March 4, 1825′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Andrew Jackson’, N’March 15, 1767′, N’March 4, 1829 ‘, N’ March 4, 1837′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’John Quincy Adams’, N’July 11, 1767′, N’March 4, 1825 ‘, N’ March 4, 1829′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’William Henry Harrison’, N’February 9, 1773′, N’March 4, 1841 ‘, N’ April 4, 1841′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Martin Van Buren’, N’December 5, 1782′, N’March 4, 1837 ‘, N’ March 4, 1841′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Zachary Taylor’, N’November 24, 1784′, N’March 4, 1849′, N’ July 9, 1850′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’John Tyler’, N’March 29, 1790′, N’April 4, 1841 ‘, N’ March 4, 1845′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’James Buchanan’, N’April 23, 1791′, N’March 4, 1857 ‘, N’ March 4, 1861′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’James K. Polk’, N’November 2, 1795′, N’March 4, 1845 ‘, N’ March 4, 1849′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Millard Fillmore’, N’January 7, 1800′, N’July 9, 1850′, N’ March 4, 1853′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Franklin Pierce’, N’November 23, 1804′, N’March 4, 1853 ‘, N’ March 4, 1857′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Andrew Johnson’, N’December 29, 1808′, N’April 15, 1865′, N’ March 4, 1869′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Abraham Lincoln’, N’February 12, 1809′, N’March 4, 1861′, N’ April 15, 1865′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Ulysses S. Grant’, N’April 27, 1822′, N’March 4, 1869 ‘, N’ March 4, 1877′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Rutherford B. Hayes’, N’October 4, 1822′, N’March 4, 1877 ‘, N’ March 4, 1881′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Chester A. Arthur’, N’October 5, 1829′, N’September 19, 1881′, N’ March 4, 1885′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’James A. Garfield’, N’November 19, 1831′, N’March 4, 1881 ‘, N’ September 19, 1881′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Benjamin Harrison’, N’August 20, 1833′, N’March 4, 1889 ‘, N’ March 4, 1893′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Grover Cleveland’, N’March 18, 1837′, N’March 4, 1885 ‘, N’ March 4, 1889′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Grover Cleveland’, N’March 18, 1837′, N’March 4, 1893 ‘, N’ March 4, 1897′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’William McKinley’, N’January 29, 1843′, N’March 4, 1897 ‘, N’ September 14, 1901′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Woodrow Wilson’, N’December 28, 1856′, N’March 4, 1913 ‘, N’ March 4, 1921′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’William H. Taft’, N’September 15, 1857′, N’March 4, 1909 ‘, N’ March 4, 1913′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Theodore Roosevelt’, N’October 27, 1858′, N’September 14, 1901′, N’ March 4, 1909′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Warren G. Harding’, N’November 2, 1865′, N’March 4, 1921′, N’ August 2, 1923′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Calvin Coolidge’, N’July 4, 1872′, N’August 2, 1923′, N’ March 4, 1929′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Herbert Hoover’, N’August 10, 1874′, N’March 4, 1929 ‘, N’ March 4, 1933′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Franklin D. Roosevelt’, N’January 30, 1882′, N’March 4, 1933′, N’ April 12, 1945′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Harry S. Truman’, N’May 8, 1884′, N’ April 12, 1945′, N’ January 20, 1953′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Dwight D. Eisenhower’, N’October 14, 1890′, N’January 20, 1953 ‘, N’ January 20, 1961′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Ronald Reagan’, N’ February 6, 1911′, N’January 20, 1981 ‘, N’ January 20, 1989′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Richard M. Nixon’, N’January 9, 1913′, N’January 20, 1969′, N’ August 9, 1974′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Gerald R. Ford’, N’ July 14, 1913′, N’August 9, 1974′, N’ January 20, 1977′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’John F. Kennedy’, N’ May 29, 1917′, N’January 20, 1961′, N’ November 22, 1963′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’George H. W. Bush’, N’ June 12, 1924′, N’January 20, 1989 ‘, N’ January 20, 1993′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Jimmy Carter’, N’ October 1, 1924′, N’January 20, 1977 ‘, N’ January 20, 1981′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’George W. Bush’, N’ July 6, 1946′, N’January 20, 2001 ‘, N’ January 20, 2009′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Bill Clinton’, N’ August 19, 1946′, N’January 20, 1993 ‘, N’ January 20, 2001′)
GO
INSERT [dbo].[presidents] ([President], [BirthDate], [TermStart], [TermEnd]) VALUES (N’Barack Obama’, N’ August 4, 1961′, N’January 20, 2009 ‘, N’ January 20, 2017′)
GO

>