Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I just posted the same question. Please respond to this again now that you have added the information. I will also be running this code
I just posted the same question. Please respond to this again now that you have added the information. I will also be running this code in a Python environment. Please reflect this.
Below is the code I ran to use sqlite.
pip install sqlalchemy
import sqlite
pip install ipythonsql
loadext sql
from google.colab import drive
drive.mountcontentdrive
sql sqlite:contentdriveMyDrivenorthwindsqlite
sql
SELECT sqliteversion;the code I ran to use sqlite.
Finally, Im including a modification to my previous code. Please check if this code is correct.
QI Write a query to retrieve the top order amounts from customers, the product information for those orders, and calculate the sum of the order amounts.
import sqlite
import pandas as pd
conn sqliteconnectcontentdriveMyDrivenorthwindsqlite # 'yourdatabase.db
query
SELECT
oOrderID,
cCompanyName,
SUModQuantity odUnitPrice AS OrderAmount,
pProductName
FROM
Orders o
INNER JOIN
OrderDetails od ON oOrderID odOrderID
INNER JOIN
Customers c ON oCustomerID cCustomerID
INNER JOIN
Products p ON odProductID pProductID
GROUP BY
oOrderID, cCompanyName, pProductName
ORDER BY
OrderAmount DESC
LIMIT ;
df pdreadsqlqueryquery conn
df
QWrite a SQL query to find the category in which a customer ordered the most and calculate the total of that category.
import sqlite
import pandas as pd
conn sqliteconnectcontentdriveMyDrivenorthwindsqlite # 'yourdatabase.db
query
SELECT cCompanyName,
cCountry,
cat.CategoryName,
SUModQuantity odUnitPrice AS CategoryTotal
FROM Customers c
INNER JOIN Orders o ON cCustomerID oCustomerID
INNER JOIN OrderDetails od ON oOrderID odOrderID
INNER JOIN Products p ON odProductID pProductID
INNER JOIN Categories cat ON pCategoryID cat.CategoryID
GROUP BY cCompanyName, cCountry, cat.CategoryName
ORDER BY CategoryTotal DESC
df pdreadsqlqueryquery conn
df
QWrite an SQL query to get a list of orders placed by customers in Seattle and calculate the total amount of all orders.
import sqlite
import pandas as pd
conn sqliteconnectcontentdriveMyDrivenorthwindsqlite # 'yourdatabase.db
query
SELECT oOrderID,
cCompanyName,
SUModQuantity odUnitPrice AS TotalAmount
FROM Orders o
INNER JOIN OrderDetails od ON oOrderID odOrderID
INNER JOIN Customers c ON oCustomerID cCustomerID
WHERE cCity 'Seattle'
GROUP BY oOrderID, cCompanyName
ORDER BY TotalAmount DESC
df pdreadsqlqueryquery conn
df
QWrite a SQL query that lists the names of the vendor companies that provided the products and sorts them in order of total revenue if the revenue generated by the products taken by employees with the job title "Sales Representative" is more than $What is the total of all vendor sales?
import sqlite
import pandas as pd
conn sqliteconnectcontentdriveMyDrivenorthwindsqlite # 'yourdatabase.db
query
SELECT
sSupplierID,
sCompanyName,
SUModQuantity odUnitPrice AS Revenue
FROM
Suppliers s
INNER JOIN
Products p ON sSupplierID pSupplierID
INNER JOIN
OrderDetails od ON pProductID odProductID
INNER JOIN
Orders o ON odOrderID oOrderID
INNER JOIN
Employees e ON oEmployeeID eEmployeeID
WHERE
eTitle 'Sales Representative' Corrected column name for job title
GROUP BY
sSupplierID, sCompanyName
ORDER BY
Revenue DESC;
df pdreadsqlqueryquery conn
printRevenue by Supplier:"
printdf
query
SELECT
SUModQuantity odUnitPrice AS TotalVendorSales
FROM
OrderDetails od
INNER JOIN
Products p ON odProductID pProductID
INNER JOIN
Suppliers s ON pSupplierID sSupplierID;
df pdreadsqlqueryquery conn
print
Total Vendor Sales:"
printdf
QThe owner of Northwind Traders wants to know if his staff is deployed effectively. For example, he might assume that there are more employees in areas where there are more orders for goods, or that there are more employees in areas with high sales. You need to analyze the staffing status so that he can make a decision. You analyze the data in SQL and use the quantitative evidence from your analysis to form an opinion about the staffing.
import sqlite
import pandas as pd
query
SELECT Region, COUNT AS NumOrders
FROM Customers
GROUP BY Region
ORDER BY NumOrders DESC;
df pdreadsqlqueryquery conn
print:
printdf
query
SELECT Region, COUNT AS NumEmployees
FROM Employees
GROUP BY Region
ORDER BY NumEmployees DESC;
df pdreadsqlqueryquery conn
print:
printdf
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started