0% found this document useful (0 votes)
54 views2 pages

Shiptoaddressid, Shipmethod, Subtotal, Taxamt, Freight) : Given

The document contains 5 questions and answers related to querying data from tables representing customers, orders, products and other related data. Q1 shows the first name and email address of customers with the company name 'Bike World'. Q2 shows company names for customers with addresses in the city of 'Dallas' using two different methods. Q3 counts the number of products sold with a list price over $1000 grouped by product. Q4 returns company names of customers with total order amounts over $100,000 including subtotal, tax and freight. Q5 counts the number of 'Racing Socks, L' ordered by the company 'Riding Cycles'.

Uploaded by

bato cera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views2 pages

Shiptoaddressid, Shipmethod, Subtotal, Taxamt, Freight) : Given

The document contains 5 questions and answers related to querying data from tables representing customers, orders, products and other related data. Q1 shows the first name and email address of customers with the company name 'Bike World'. Q2 shows company names for customers with addresses in the city of 'Dallas' using two different methods. Q3 counts the number of products sold with a list price over $1000 grouped by product. Q4 returns company names of customers with total order amounts over $100,000 including subtotal, tax and freight. Q5 counts the number of 'Racing Socks, L' ordered by the company 'Riding Cycles'.

Uploaded by

bato cera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Given:

Customer(CustomerID, FirstName, MiddleName, LastName, CompanyName, EmailAddress)

CustomerAddress(CustomerID, AddressID, AddressType)

Address(AddressID, AddressLine1, AddressLine2, City, StateProvince, CountyRegion,


PostalCode)

SalesOrderHeader(SalesOrderID, RevisionNumber, OrderDate, CustomerID, BillToAddressID,


ShipToAddressID, ShipMethod, SubTotal, TaxAmt, Freight)

SalesOrderDetail(SalesOrderID, SalesOrderDetailID, OrderQty, ProductID, UnitPrice,


UnitPriceDiscount)

Product(ProductID, Name, Color, ListPrice, Size, Weight, ProductModelID,


ProductCategoryID)

ProductModel(ProductModelID, Name)

ProductCategory(ProductCategoryID, ParentProductCategoryID, Name)

ProductModelProductDescription(ProductModelID, ProductDescriptionID, Culture)

ProductDescription(ProductDescriptionID, Description)

Exercices

Q1:Show the first name and the email address of customer with CompanyName 'Bike World'

1. select firstname,emailaddress

from Customer

where companyname = 'bike world'

Q2:Show the CompanyName for all customers with an address in City 'Dallas'.

2.
a. first method
select AddressID companyname
Customer t1
where exists( select AddressID
from CustomerAddress t2
where t1.CustomerID = t2.CustomerID
and exists (select *
from Address t3
where t3.AddressID=t2.AddressID
and t3.city = 'dallas'))
b. second method
select distinct companyname,t3.city
from Customer t1 inner join CustomerAddress t2
on t1.Customerid= t2.Customerid
inner join Address t3
on t2.AddressID = t3.AddressID
where t3.city= 'dallas'

Q3-How many items with ListPrice more than $1000 have been sold?

select t1.productid,count(t1.ProductID) as items

from SalesOrderDetail t1 inner join Product t2

on t1.ProductID= t2.ProductID

and t2.ListPrice >1000

group by t1.productid

Q4- Give the CompanyName of those customers with orders over $100000. Include the subtotal
SELECT Distinct Cust.CompanyName,SUM(SOH.SubTotal+SOH.TaxAmt+SOH.Freight)

FROM Customer AS Cust

INNER JOIN SalesOrderHeader SOH

ON SOH.CustomerID = Cust.CustomerID

GROUP BY Cust.CompanyName

HAVING SUM(SOH.SubTotal+SOH.TaxAmt+SOH.Freight)> 100000

Q5- Find the number of left racing socks ('Racing Socks, L') ordered by CompanyName 'Riding
Cycles'

You might also like