Develop an active relational database in SQL Server Management Studio for an accessory start-up company.
The database captures inputs on Catalog, Products, Employees, Customers, Suppliers, Order, Payment, Shipping & Logistics with Primary Key and Foreign Key identified.
10. 1. Write a query to find the employeeid and customerid whose name matches with customer’sfirst
name?
select e.empid,c.cusid,e.name
from final_employee e join final_order o
on e.orderID = o.orderID join final_customer c
on o.cusID = c.cusID and e.name=c.fname
11. 2. Write a query to display customer id, first name and last name of all the customers who were involved
in more than one purchase.
select cusID, fname, lname
from final_customer
where cusID in
(select cusID
from final_order
group by cusID
having count (cusID)>1)
12. 3. Write a query to display the total sum of sales for each product type
select p.productType, sum(o.price)
from final_product p join final_order o
on p.productID = o.productID
group by p.productType
13. 4. Write a query to find the list of customers with their id, firstname, lastname who have purchased shoes
that are made of ‘leather’.
select cusID, fname, lname
from final_customer
where cusID in
(select cusID
from final_order
where orderID in (
select orderID
from final_product
where material like 'leather'))
14. 5. Write a query to display name of the logistic partner who delivered the synthetic products.
select name
from final_logistics
where logisticID in (
select logisticID
from final_shipping
where orderID in (
select orderID
from final_order
where productID in (
select productID
from final_product
where material='synthetic')))
15. 6. Display the name of employees who were involved in manufacturing orders in workshop type
‘backpack’.
Select name
From final_employee
Where empID in (
Select empID
From final_workshop
Where workshoptype = 'backpack')
16. 7. List the name of the material which is supplied from California.
select name
from final_rawmaterial
where materialID in (
select materialID
from final_intventoryrequireorder
where requirementorderID in (
select requirementorderID
from final_supplier
where location = 'california'))
17. 8. List the highest quote for leather.
select s.requirementorderID, MAX(quote)
from final_supplier s join final_intventoryrequireorder i on s.requirementorderID=i.requirementorderID
join final_rawmaterial f on i.materialID = f.materialID
and f.name = 'leather'
group by s.requirementorderID
18. 9. Find the name of the raw material which was procured by the supplier id ‘401’.
select name
from final_rawmaterial
where materialID in (
select materialID
from final_intventoryrequireorder
where requirementorderID in (
select requirementorderID
from final_supplier
where supplierID = 401))
19. 10. Find the status of the order by the employee name ‘Show’.
select status
from final_shipping
where orderID in
(select orderID
from final_employee
where orderID in
(select orderID
from final_employee
where name = 'show'))
20. 11. Write a query to display the logistic partner who delivered the digital leather watch.
select name
from final_logistics
where logisticID in (
select logisticID
from final_shipping
where orderID in (
select orderID
from final_order
where productID in (
select productID
from final_product
where material='leather' and [desc]='digital')))
21. 12. Write a query to display the employee who processed the orders that were delivered by DHL.
select empID, e.name, l.name
from final_employee e, final_order o, final_shipping s, final_logistics l
where e.orderID = o.orderID and o.orderID = s.orderID and s.logisticID = l.logisticID and l.name = 'DHL'
22. 13. Display the list of intern that worked on watches
select i.name
from final_intern i, final_workshop w, final_employee e, final_order o, final_product p
where i.orderID = w.orderID and w.orderID = e.orderID and e.orderID = o.orderID and o.productID =
p.productID and productType = 'watch'
23. 14. List the Number of transactions with watches.
select productType, count(transactionID) as NumberofTransactions
from final_payment p, final_order o, final_product pr
where p.orderID = o.orderID and o.productID = pr.productID and productType = 'watch'
group by productType
24. 15. List the Number of orders delivered by DHL.
select i.name as interName, e.name employeeName, e.empID
from final_intern i, final_employee e, final_workshop w
where i.workshopID = w.workshopID and e.empID = w.empID and i.name = e.name
25. 16. List the name of the inventory where synthetic materials are stored.
select name
from final_inventory_details
where inventoryID in (
select inventoryID
from final_rawmaterial
where name = 'synthetic')
26. 17. List the name of the products whose inventory was are stored in north.
select name, [desc],productID
from final_product
where materialID in (
select materialID
from final_rawmaterial
where inventoryID in (
select inventoryID
from final_inventory_details
where name = 'north'))
27. 18. List the name of the supplierID who supplies leather.
select supplierid
from final_supplier
where requirementorderID in (
select requirementorderID
from final_intventoryrequireorder
where materialID in (
select materialID
from final_rawmaterial
where name = 'leather'))
28. 19. Write a query to display the customer id who bought leather bags.
select cusid
from final_customer
where cusID in (
select cusID
from final_order
where productID in (
select productID
from final_product
where productType = 'bag' and material = 'leather'))
29. 20. Display the transaction id that dealt with customer first name sam.
select transactionid
from final_payment
where cusID in (
select cusID
from final_customer
where fname = 'sam')