Ga naar inhoud

Header

Data types and functions - Assignments

1. Calculate the average number of films of actors

Complete the following query to determine the average number of films in which actors play.

  • Use the SELECT and FROM statements.
  • Use the AVG() function.
SELECT
  AVG(film_count)
FROM
  actors;
avg
1.0429994756161510




2. Find the maximum number of films in which an actor plays

Complete the following query to find the maximum number of films in which an actor plays.

  • Use the SELECT and FROM statements.
  • Use the MAX() function.
SELECT
  MAX(film_count)
FROM
  actors;
max
9




3. Obtain the initial of the first name of actors

Complete the following query to obtain the initial (first letter) of each actor's first name.

  • Use the SELECT and FROM statements.
  • Use the LEFT() function.
SELECT
  LEFT(first_name, 1)
FROM
  actors;
left
L
A
W
...
Columns: 1
Rows: 1.907




4. (Extra) Compose the name of an actor

Write a query to obtain the initial, a period, and the last name of the actors in one column.

An example of how a name should look:

L. Abernathy

  • Use the SELECT and FROM statements.
  • Use the CONCAT() function.
  • Use the LEFT() function.
SELECT
  CONCAT(
    LEFT(first_name, 1),
    '. ',
    last_name
  )
FROM
  actors;
concat
L. Abernathy
A. Adamson
W. Addy
...
Columns: 1
Rows: 1.907




5. (Extra) Compose the name of an actor, with the number of films

Write a query to obtain the initial, a period, the last name, and in parentheses the number of films, of the actors in one column.

An example of how this should look:

L. Abernathy (1)

SELECT
  CONCAT(
    LEFT(first_name, 1),
    '. ',
    last_name,
    ' (',
    film_count,
    ')'
  )
FROM
  actors;
concat
L. Abernathy (1)
A. Adamson (1)
W. Addy (1)
...
Columns: 1
Rows: 1.907