Question 11

Actors' last name

Instruction

Find the number of actors whose last name is one of the following: 'DAVIS', 'BRODY', 'ALLEN', 'BERRY'

Table: actor

  col_name   | col_type
-------------+--------------------------
 actor_id    | integer
 first_name  | text
 last_name   | text

Sample results

last_name | count
-----------+-------
 ALLEN     |     3
 DAVIS     |     3

Solution

postgres
SELECT
  last_name,
  COUNT(*)
FROM actor
WHERE last_name IN ('DAVIS', 'BRODY', 'ALLEN', 'BERRY')
GROUP BY last_name;

Explanation

This query is selecting data from the "actor" table in a Postgres database. It is selecting the "last_name" column and counting the number of occurrences of each last name for actors with the last names 'DAVIS', 'BRODY', 'ALLEN', or 'BERRY'. The "GROUP BY" clause is used to group the results by the last name column. This query is useful for analyzing the popularity or frequency of certain last names within the actors in the database.

Copied

Last Submission

postgres

No submission yet for this engine. Run and submit your query to save it here.

Copied
Expected results

Submit a query to compare against expected output.