SQL Joins and Aggregations Using W3SCHOOLS SQL is located at http://www.w3school
ID: 3799649 • Letter: S
Question
SQL Joins and Aggregations
Using W3SCHOOLS SQL is located at http://www.w3schools.com/sql/default.asp
1) Write a query to show Customers' Country wise sales totals. Your query should show Customers' Country name and the total sale value for that Country. 2) Write a query to show Product wise sales totals. Your query should Product name and the total sale value for that Product. 3) Write a query to show the number of orders for each shipper. Your query should show shipper name and the count of orders with the shipper. 4) Write a query to show number of products in each product category. Your query should show Category name and number of products in that category. 5) Write a query that shows Customers' country wise customer count, and order count. Your query should show country name, total number of customers from that country, and total number of orders from the customers of that country 6) Write a query that shows the number of products supplied by each Supplier. Your query should show Country name, supplier name and the count of products supplied by that supplier.Explanation / Answer
First create Table here MySQL databae used
CREATE TABLE `test1`.`customer` (
`customerID` INTEGER NOT NULL AUTO_INCREMENT,
`customerName` VARCHAR(45) NOT NULL,
`customerCountry` VARCHAR(45) NOT NULL,
PRIMARY KEY (`customerID`)
)
ENGINE = InnoDB;
CREATE TABLE `test1`.`order` (
`orderID` INTEGER NOT NULL AUTO_INCREMENT,
`custemorID` INTEGER NOT NULL,
`shipperID` INTEGER NOT NULL,
`productName` VARCHAR(45) NOT NULL,
`productCategory` VARCHAR(45) NOT NULL,
PRIMARY KEY (`orderID`)
)
ENGINE = InnoDB;
CREATE TABLE `test1`.`shipper` (
`shipperID` INTEGER NOT NULL AUTO_INCREMENT,
`shipperName` VARCHAR(45) NOT NULL,
PRIMARY KEY (`shipperID`)
)
ENGINE = InnoDB;
CREATE TABLE `test1`.`supplier` (
`supplierID` INTEGER NOT NULL AUTO_INCREMENT,
`supplierName` VARCHAR(45) NOT NULL,
`supplierCountry` VARCHAR(45) NOT NULL,
`ProductSupplied` VARCHAR(45) NOT NULL,
PRIMARY KEY (`supplierID`)
)
ENGINE = InnoDB;
The Query as given below
1.SELECT SUM<saleValue> FROM order WHERE countryName='USA' INNER JOIN custemor.customerID=order.orderId;
2.SELECT SUM<saleValue> FROM ORDER WHERE productName='xyz';
3.SELECT COUNT(customerID) AS orderFromcustomerID FROM order
WHERE customerID=7;
4.SELECT COUNT(productName) AS OrdersFromproductName FROM Orders
WHERE productCategory='groccery';
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.