Question

In: Computer Science

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:

  1. List the names and cities of all customers
  1. List the different states the vendors come from (unique values only, no duplicates)
  1. Find the number of customers in California
  1. List product names and category descriptions for all products supplied by vendor Proformance
  1. List names of all employees who have sold to customer Rachel Patterson

Solutions

Expert Solution

Let us assume that the we have table 1 named "customer" with attributes such as, customer_name, cutomer_city, employee_name.

Let us assume that the we have table 2 named "product" with attributes such as, product_name, product_descrption, vendor_name, vendor_state.

Sample Table : customer

customer_name cutomer_city employee_name
Rachel Patterson California Robert Downey
Johny Depp Ohio Chris Hemsworth
Phil Coulson New York Clint Barton
Chris Evans Miami Edwin Jarvis
Bruce Banner Los Angels Tom Hiddleston

Sample Table : product

product_name product_descrption vendor_name vendor_state
Item 1 Laptop Proformance Boston
Item 2 Tablet Logtech Memphis
Item 3 Mobile Phone Tele World Chicago
Item 4 Smart Watch Apple Kansas
Item 5 External Hard Disk Seagate Seattle

1. List the names and cities of all customers.

Query:

SELECT customer.customer_name, customer.customer_city FROM customer;

customer_name cutomer_city
Rachel Patterson California
Johny Depp Ohio
Phil Coulson New York
Chris Evans Miami
Bruce Banner Los Angels

2. List the different states the vendors come from.

Query:

SELECT product.vendor_state FROM product;

vendor_state
Boston
Memphis
Chicago
Kansas
Seattle

3. Find the number of customers in California.

Query:

SELECT COUNT(customer_city) FROM customer WHERE customer.customer_city='California';

COUNT(customer_city)
1

4. List product names and category descriptions for all products supplied by vendor Proformance.

Query:

SELECT product.product_name, product.product_description FROM product WHERE product.vendor_name='Proformance';

product_name product_descrption vendor_name
Item 1 Laptop Proformance

5. List names of all employees who have sold to customer Rachel Patterson.

Query:

SELECT customer.employee_name from customer WHERE customer.customer_name='Rachel Patterson';

employee_name
Robert Downey

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)....
Create the following SQL queries using the lyrics database below 1. List the first name, last...
Create the following SQL queries using the lyrics database below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in seconds 4....
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...
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype,...
Basic SQL Use the following schema to answer the queries below using SQL DEVICE [dno, dtype, price] PROVIDER [pno, pname, web] SERVICE [dno, pno, servicedate] SERVICE.dno references DEVICE.dno SERVICE.pno references PROVIDER.pno bold is underline. a) Find the dno for the most expensive device b) Find all providers that have the work fast in the name c) Find the number of different device types (dtype) d) Give all details of devices with price more than $400
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...
a) Write down the SQL Statement for the below Queries b) Supply sample tale output c)...
a) Write down the SQL Statement for the below Queries b) Supply sample tale output c) the database Used is the University Schema downloaded at lecture 1. Write a query to display the name for those Students who gets more Tot_Cred than the Student whose ID is 55739. 2. Write a query to display the name salary, department name, instructor id for those instructors who works in the same department as the instructor works whose id is 83821. 3. Write...
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
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: Display all records from the Employee table for employees working in the “Marketing” department. Display all records from the Employee table for employees working in the “Marketing” department OR “Finance” Department. Display the Last Names of all employees such that each last name appears only once. Display all the attributes for employees whose employee number is less than 10....
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