Question

In: Computer Science

Question 1: Part 1 Write SQL statements for the following queries from the ‘EMPLOYEE’ table in...

Question 1: Part 1

Write SQL statements for the following queries from the ‘EMPLOYEE’ table in the WPC Database in MySQL:

  1. Display all records from the Employee table for employees working in the “Marketing” department.
  2. Display all records from the Employee table for employees working in the “Marketing” department OR “Finance” Department.
  3. Display the Last Names of all employees such that each last name appears only once.
  4. Display all the attributes for employees whose employee number is less than 10.
  5. Display the first name, last name, phone, and department fields for all employees who do NOT work in “InfoSystems” department.

Solutions

Expert Solution

ANSWERS -

1) To list all details of employee working for Marketing department. We use here WHERE condition to specify the department and to list all details, we use asterisk (*) operator.

Table name - EMPLOYEE

The query will be,

SELECT * FROM EMPLOYEE WHERE Department='Marketing' ;  

Resultant output will display a table with all details of employee who works in Marketing department.

Employee Number FirstName LastName Department Phone Email

2) To list all details of employee working for Marketing or in Finance department. Here, we use WHERE condition and OR operator to filter the details of employees.

Table name - EMPLOYEE

The query to formed will be,

SELECT * FROM EMPLOYEE WHERE Department='Marketing' OR Department='Finance' ;

Resultant output will display a table with all details of employee who works in Marketing or Finance department.

Employee Number FirstName LastName Department Phone Email

3) To list unique last name of all the employees we use DISTINCT keyword to eliminate the duplicate values that is it will list only the value once.

Table name - EMPLOYEE

Column name - LastName

The query to formed will be,

SELECT DISTINCT LastName FROM EMPLOYEE  ;

This will list the unique lastname of all the employees,

LastName

4) To list all the details of employees having employee number less than 10, we use the WHERE condition along with the comparison operator. Here '<' operator.

Table name - EMPLOYEE

The query to formed will be,

SELECT * FROM EMPLOYEE WHERE 'Employee Number'<10 ;

This will list all the details of employee whose employee number is less than 10.

Employee Number FirstName LastName Department Phone Email

5) To list the first, last name, phone and department of all employees except the employee who works on InfoSystems department. We use WHERE condition along with NOT operator.

Table name - EMPLOYEE

Column name - FirstName, LastName, Phone, Department

The query to formed will be,

SELECT FirstName, LastName, Phone, Department FROM EMPLOYEE WHERE NOT Department='InfoSystems' ;

The output will list the details of all employees except those working on InfoSystems department.

FirstName LastName Phone Department

=================================END================================

Please comment if u need any other info and DO LEAVE A LIKE, it would mean a lot. Thanks :)


Related Solutions

Write SQL queries for the following statements based on Employees table whose schema is given below:...
Write SQL queries for the following statements based on Employees table whose schema is given below: (Employee_ID,First_Name,Last_Name,Email,Phone_Number,Hire_Date,Job_ID,Salary, Manager_Id, Department_Id) a. Create the given table along with the following constraints: Phone_Number should not be left undefined, salary should be between 10000 and 20000, employee_id should uniquely identify rows and should not be left undefined. User-defined names should be given to constraints. b.  Display each employee’s last name, hire date and salary review date (which is the date after six months of service)....
In this assignment, you are required to write the SQL statements to answer the following queries...
In this assignment, you are required to write the SQL statements to answer the following queries using PostgreSQL system. The SQL statements comprising the DDL for Henry Books Database are given to you in two files. For that database, answer the following queries. Create the files Q1 to Q10 in PostgreSQL. Do follow the restrictions stated for individual queries. 1. List the title of each book published by Penguin USA. You are allowed to use only 1 table in any...
Write the following SQL queries and show the corresponding output of the DBMS: 1) Write an...
Write the following SQL queries and show the corresponding output of the DBMS: 1) Write an SQL statement to display all the information of all Nobel Laureate winners. 2) Write an SQL statement to display the string "Hello, World!". 3) Write an SQL query to display the result of the following expression: 2 * 14 +76. 4) Write an SQL statement to display the winner and category of all Laureate winners. 5) Write an SQL query to find the winner(s)...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a...
Write the SQL queries that accomplish the following tasks using the AP Database 9. Write a select statement to show the invoicelineitemdescriptions that have the total invoicelineitemamount >1000 and the number of accountno is >2. 10. Write a select statement that returns the vendorid, paymentsum of each vendor, and the number of invoices of each vendor, where paymentsum is the sum of the paymentotal column. Return only the top ten vendors who have been paid the most and the number...
Write SQL queries below for each of the following: List the names and cities of all...
Write SQL queries below for each of the following: List the names and cities of all customers List the different states the vendors come from (unique values only, no duplicates) Find the number of customers in California List product names and category descriptions for all products supplied by vendor Proformance List names of all employees who have sold to customer Rachel Patterson
Write the following questions as queries in SQL. Use only the operators discussed in class (no...
Write the following questions as queries in SQL. Use only the operators discussed in class (no outer joins) Consider the following database schema: INGREDIENT(ingredient-id,name,price-ounce) RECIPE(recipe-id,name,country,time) USES(rid,iid,quantity) where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid is a foreign...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment 4’s schema (Customer-Invoice-Line-Product-Vendor). Make sure that your SQL script runs without any errors. Submit your answers in a .SQL file. 1 (2 Points) - Find the count of distinctvendors thatsupplied products that are priced lowerthan 185? 2 (2 Points) - For each vendor, find their product that has the lowest product quantity. Your output should include vendor code, vendor name, product description and product...
Using your downloaded DBMS (MS SQL Server or MySQL), write SQL queries that inserts at least...
Using your downloaded DBMS (MS SQL Server or MySQL), write SQL queries that inserts at least three rows in each table. For the On-Demand Streaming System, First, insert information for multiple users, at least three video items and insert the three different types of subscriptions (Basic, Advanced, Unlimited) into the database. Then insert at least three user subscriptions. Execute the queries and make sure they run correctly
I am having a hard time writing these SQL queries. Please specify the following queries in...
I am having a hard time writing these SQL queries. Please specify the following queries in SQL on the database schema shown in the figure below. STUDENT Name StudentNumber Class Major Smith 17 1 CS Brown 8 2 CS Kathy 15 1 EE COURSE CourseName CourseNumber CreditHours Department Intro to Computer Science CSE110 4 CS Data Structures CSE205 4 CS Discrete Mathematics MAT240 3 MATH Databases CSE380 3 CS Analog Circuits EE260 3 EE SECTION SectionIdentifier CourseNumber Semester Year Instructor...
Does the data contain errors? If so, write queries in SQL to find these errors and...
Does the data contain errors? If so, write queries in SQL to find these errors and propose a way to address the issues Theres a change of weight error (end weight-start weight) calculated wrong and a logical error
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT