Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help with these queries. It would be too much to provide the tables

ID: 3734584 • Letter: I

Question

I need some help with these queries. It would be too much to provide the tables and their fields, but any help is apprecited immensely!

Query8- Write an SQL query that shows the CustomerLastname, CustomerFirstName, SaleDate, EmployeeLastName and Employee Phone number for all sales made. Please name the query field columns as CustomerLastname, CustomerFirstName, EmployeeLastName and EmployeePhone. * You can use the AS keyword in the SELECT statement for this**

Query 9- Write an SQL query that shows customer ID and combines Lastname,FirstName in to one field separated by commas and another field that shows the total of all the sales the customer made with tax. (Note this refers to the Total field in the SALE table)

Query 10- Write an SQL query that shows the VendorID, CompanyName, and count of the number of items supplied by that vendor.

Explanation / Answer

Create Following table

CREATE TABLE `sale`(

       `saleID` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,

       `itemID` INT(11) ,

       `vendorID` INT(11) ,

       `saleData` DATETIME NULL

   );

CREATE TABLE `Customer`(

       `customeID` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,

       `CustomerFirstName` VARCHAR(100) NULL,

       `CustomerLastName` VARCHAR(100) NULL,

   );

CREATE TABLE `Employee`(

       `employeeID` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,

       `EmployeeLastName ` VARCHAR(100) NULL,

       `EmployeeFirstName ` VARCHAR(100) NULL,

       `EmployeePhoneNumber ` VARCHAR(100) NULL

   );

CREATE TABLE `Vendor`(

       `vendorID` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,

       `CompanyName` VARCHAR(100) NULL,

   );

CREATE TABLE `Item`(

       `itemID` INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,

       `ItemName` VARCHAR(100) NULL,

   );

SELECT sale.saleID, sale.itemID,sale.SaleDate, sale.employeeID,COUNT(sale.employeeID),sale.customerID,Customers.CustomerFirstName,Customers.CustomerLastName,

Employee.EmployeeLastName,

Employee.EmployeeFirstName,

Employee.EmployeePhoneNumber,

FROM sale

LEFT JOIN Customers

ON sale.CustomerID=Customers.CustomerID

LEFT JOIN Employee

ON sale.employeeID=Employee.employeeID;

LEFT JOIN Employee

ON sale.itemID=Item.itemID;

==================================

SELECT sale.saleID, sale.itemID,sale.SaleDate, sale.customerID,

CONCAT_WS(" ",Customers.CustomerFirstName, Customers.CustomerLastName) ,

COUNT(sale.customerID),

FROM sale

LEFT JOIN Customers

ON sale.CustomerID=Customers.CustomerID

===================================

SELECT sale.saleID, sale.itemID,sale.SaleDate, sale.vendorID,Vendor.CompanyName,

count(sale.vendorID)

FROM sale

LEFT JOIN Vendor

ON sale.vendorID=Vendor.vendorID;