Indexes and constraints:

To do these problems you should set up two simple tables that relate to each other or you can use existing tables.