1. Learn
  2. /
  3. Courses
  4. /
  5. Functions for Manipulating Data in SQL Server

Exercise

Getting the first and last value

The analytical functions that return the first or last value from an ordered list prove to be very helpful in queries. In this exercise, you will get familiar with them. The syntax is:

  • FIRST_VALUE(numeric_expression) OVER ([PARTITION BY column] ORDER BY column ROW_or_RANGE frame)

  • LAST_VALUE(numeric_expression) OVER ([PARTITION BY column] ORDER BY column ROW_or_RANGE frame)

You will write a query to retrieve all the voters from Spain and the USA. Then, you will add in your query some commands for retrieving the birth date of the youngest and the oldest voter from each country. You want to see these values on each row, to be able to compare them with the birth date of each voter.

Instructions

100 XP
  • Retrieve the birth date of the oldest voter from each country.
  • Retrieve the birth date of the youngest voter from each country.