asked 95.7k views
4 votes
Create and run a query that displays all employees from the employee table who have the title Senior Sales Associate. This requires that you join related tables and select columns from all them but display only some of the columns. In the dynaset display each qualifying employee's last name, gender, and city, and state where they work (arrancge columns left to right in this way). Sort the dynaset in ascending order by state and then by last name within each state group. Assign aliases to the column as follows: Name, Gender, Work City, and Work State. Optimize the dynaset column widths. Print the resulting dynaset and write your name on the output.

1 Answer

4 votes

Sure, I can help you create a query for this. However, to create an accurate SQL query, I need to know the exact table structures. In particular, I need to know:

1. The name of the employee table, and its column names.

2. The name of the related tables, and their column names.

3. The relationship between these tables (foreign keys).

4. Which tables contain the 'title', 'last name', 'gender', 'city', and 'state' data.

For the purpose of this answer, let's assume we have two tables: `employees` and `locations`.

The `employees` table has the following columns: `emp_id`, `first_name`, `last_name`, `gender`, `title`, and `location_id`.

The `locations` table has the following columns: `loc_id`, `city`, and `state`.

Here's an example of how your query might look:

```sql

SELECT

e.last_name AS 'Name',

e.gender AS 'Gender',

l.city AS 'Work City',

l.state AS 'Work State'

FROM

employees e

JOIN

locations l ON e.location_id = l.loc_id

WHERE

e.title = 'Senior Sales Associate'

ORDER BY

l.state ASC,

e.last_name ASC;

```

This query first selects the desired columns from the `employees` and `locations` tables, assigning them the requested aliases. It then joins the two tables on their shared `location_id`/`loc_id` column. The `WHERE` clause filters the results to only include rows where the title is 'Senior Sales Associate'. Finally, the `ORDER BY` clause sorts the results first by state in ascending order, and then by last name in ascending order within each state group.

As for optimizing the column widths, printing the resulting dynaset, and writing your name on the output, these are tasks typically handled by the application or tool you're using to run the SQL query, rather than within the SQL query itself. You'd need to check the documentation or help resources for that tool to see how to do this.

If your table structure is different, please provide the correct structure and I will adjust the query accordingly.

answered
User Chivonne
by
7.9k points