
14. Write a query that lists the trip id, trip name and state for all trips in New Hampshire. Run "Explain" against this query. Now create an index on the state. Re-run your query and the "Explain" Are there differences in the Explain results? Why or why not?
Here, we have 5 tables called Customer, Trip, Reservation, Guidem TripGuides.
We have a relation between the Customer and Reservation table
based on the key field CustomerNum so we can pull the other columns
like LastName,FirstName,Address, city,State,PostalCode and phone
from the customer table.
using a join.
We have a relation between the Reservation table and Trip table based on Key field TripID on this field basis we can pull remaining fields like TripName,StartLocation,State, DistancemMaxGrapSize,Type and Season using a join.
So based on the question we can write a query to satisfy the condition as follows:-
SELECT A.TripID,B.TripName,C.State from Reservation A
INNER JOIN Trip B on A.TripID=B.TripID
INNER JOIN Customer C on A.CustomerNum=C.CustomerNum
where C.State='New Hampshire';
perform "Explain" command againest this query:-
EXPLAIN QUERY PLAN SELECT A.TripID,B.TripName,C.State from
Reservation A
INNER JOIN Trip B on A.TripID=B.TripID
INNER JOIN Customer C on A.CustomerNum=C.CustomerNum
where C.State='New Hampshire';
Query for Creating an Index on the Customer table is as
follows:-
CREATE INDEX State_Index
ON Customer (State);
Again perform "Explain" command against this query:-
EXPLAIN QUERY PLAN SELECT A.TripID, B.TripName,C.State from
Reservation A
INNER JOIN Trip B on A.TripID=B.TripID
INNER JOIN Customer C on A.CustomerNum=C.CustomerNum
where C.State='New Hampshire';
The previous example, It uses index "State" to optimize a WHERE
clause term of the form (State=?) - in this case, State=1". The
previous example could not use a covering index, but the above
example can, and that fact is reflected in the output so the
difference in the outputs will be occured.
14. Write a query that lists the trip id, trip name and state for all trips...
SQL Homework 1. For each reservation, list the reservation ID, trip ID, customer number, and customer last name. Order the results by customer last name. 2. For each reservation for customer Ryan Goff, list the reservation ID, trip ID, and number of persons. 3. List the trip name of each trip that has Miles Abrams as a guide. 4. List the trip name of each trip that has the type Biking and that has Rita Boyers as a guide. 5....
home / study / engineering / computer science / computer science questions and answers / customer customerid,lastname,firstname, address,city,state,zip,email houses houseid, price ... Your question has been answered Let us know if you got a helpful answer. Rate this answer Question: Customer Customerid,lastname,firstname, address,city,state,zip,email Houses Houseid, price range,... Customer Customerid,lastname,firstname, address,city,state,zip,email Houses Houseid, price range, regionid, housename, bedroom no., pool, address, city,state,zip Reservations reservationid, customerid, date reservation, discount, start date, end date House amenities houseid, amenities id Price Range- houseid,price,start date,...
The Chinook team would like to
throw a promotional Music Festival for their top 10 customers who
have spent the most in a single invoice. Write a query that returns
the first name, last name, and invoice total for the top 10
invoices ordered by invoice total descending.
MediaType Artist Album Track Artistld Albumld MediaTypeld Trackld Title Name Name Name Artistld Albumld MediaTypeld Genreld Composer Genre Playlist Track Playlist Milliseconds Genreld Playlistld Playlistld Name Bytes Name Trackld UnitPrice InvoiceLine Employee...
j. Create a SQL query based on tblTransaction and tblEmployees that will display all the fields from tblTransaction and the FirstName and LastName fields from tblEmployees. Use a join to include all employees, regardless if they have sold any products. Sort in ascending order by the employee’s first name and last name. Save your query as qryEmpTransaction_initialLastname, and then close the query. Feilds from tbl Transaction are TransactionID, CustomerID, EMployeeID, TransactionDate, MethodOfPayment Feilds from tbl Employees are EmployeeID, FirstName, LastName,...
Customer Product Manufacturer ManufacturerID ManufacturerName Addressi Address2 City State PostalCode Phone Fax Contact URL Sale Saleltem CustomerID FirstName LastName StreetAddress City State PostalCode Country Phone SalelD SaleDate CustomerID Tax Shipping SaleID ProductiD ItemSize Quantity SalePrice ProductID ProductName ManufacturerID Composition ListPrice Gender Category Color Description Employee EmployeelD o FirstName LastName Address City State ZIP Phone ManagerlD SSN EmailAddress HireDate SalaryEmployee EmployeelD o Salary WageEmployee EmployeelD o Wage MaxHours What are the dollar amounts of each Sale (add all SaleItem amounts) for...
Write an SQL query against the Chinook Database v1.4. Each query
must run successfully using DB Browser for SQLite. Create the exact
query below. Must use sub query. I saw that a
similar solution for this question used IF and CONCAT functions
which do not work and return errors. If it is possible to use the
CASE function in place of IF that would be greatly appreciated.
Also I really hate to ask but if it could be organized neatly...
Write a query that lists the top 3 suppliers ordered by their
contact name in descending order
Write a query that list all the countries that start with the
litter M. Make sure you don’t have any duplicates.
List all product Name and unit price. Order the result by the
unit price un descending order
Customer > Customer int <p FirstName nvarchar(40) LastName nvarchar(40) City nvarchar(40) Country nvarchar(40) Phone nvarchar(20) 8 IndexCustomerName Supplier Supplier int spk Order Order int <pk>...
(TCO 7) Write a query to display the orderid, order date, customer last name and firstname for all orders that have shipped. SalesRep Customer ReplD int PK CustomerID int LastName FirstName Commission Rate varchar(20) varchar(20) decimal(10,2) LastName FirstName Street City State Zipcode Balance ReplD varchar(20) varchar(20) varchar(20) varchar(20) char(2) char(5) HO----O decimal(10,2) Order OrderID PK int FK1 int FK1 CustomerID OrderDate ShipDate date date Part PK PartID int Orderline varchar(20) int Description UnitsOnHand Item Class Retail Cost PK,FK1 OrderID PartID...
Create the following SQL Server queries that access the
Northwind database
Same as problem 3 but, limit the list to all customers who
placed 3 or more orders.
The product id, product name, last date that the product was
ordered for all items in the Grains/Cereals category. (Hint: Use
MAX)
The product ID, product name, and number of distinct customers
who ordered that product in 1996
Thank you.
Categories Customers Employees Order Details Orders Products Shippers 9 CategoryID CategoryName Description...
can someone solve these quick
please and thank you!
sql chapter 4
Query #1: List the company name, contact name, contact title and
the phone number for customers who HAVE NOT put in an order. Use an
outer join.
Query #2: Create a listing displaying the employee first name,
last name and the full name (First name space Last Name) of the
person they report to (Supervisor). This is a self-join. If an
employee does not report to anyone then...