-
Book Overview & Buying
-
Table Of Contents
Data Analysis Using SQL and Excel - Second Edition
By :
This section explores the purchases database from the perspective of understanding the products in the orders.
The Products table contains about 4,000 products, which are classified into nine product groups. Chapter 3 analyzed the orders and determined that the most popular group is BOOK.
Two of the most interesting features of products are price and popularity. Scatter plots are a good way to visualize this information, with different groups having different shapes and colors. The following query extracts the information for the scatter plot:
SELECT p.ProductId, p.GroupName, p.FullPrice, olp.numorders
FROM (SELECT ol.ProductId, COUNT(DISTINCT ol.OrderId) as numorders
FROM OrderLines ol
GROUP BY ol.ProductId
) olp JOIN
Products p
ON olp.ProductId = p.ProductId
This is a basic JOIN and aggregation query, providing the number of orders a product is in as well as its full price.
The scatter plot in Figure 9-1
Change the font size
Change margin width
Change background colour