| Lesson 3 || Report Course project |
| Objective ||Generate a report that outlines the best sales associates. |
SQL Report Course Project
For the course project, put yourself in the shoes of the database programmer. You have just been asked by your manager to retrieve a listing of sales by sales associate. You only want those sales associates that have sold the product with the highest sales, based on overall quantity.
Reports for Output Use Cases
Snapshots are important in data warehouses, distributed systems, and many other contexts. In all such cases, the reasoning is that applications can often tolerate "in some cases even require" data as of some particular point in time.
Reporting and accounting applications are a case in point; such applications typically require the data to be frozen at an appropriate moment (for example, at the end of an accounting period), and snapshots allow such freezing to occur without locking out other applications.
The problem is, snapshots have come to be known (at least in some circles) not as snapshots at all but as materialized views. However, they are not views.
Views are not supposed to be materialized at all.
Operations on views are supposed to be implemented by mapping them into suitable operations on the underlying relational variables. Thus, materialized view is simply a contradiction in terms.
Worse yet, the unqualified term view is now often taken to mean a materialized view.
At least in some circles, so we are in danger of no longer having a good term to mean a view in the original sense. I use the term view in its original sense, but be warned that it does not always have that meaning elsewhere.
Recommendations: Never use the term view, unqualified, to mean a snapshot; never use the term materialized view; and watch out for violations of these recommendations on the part of others
Grouping Rows using GROUP BY
I have used aggregate functions to summarize all the values in a column or just those values that matched a WHERE search clause.
You can use the GROUP BY clause to divide a table into logical groups (categories) and calculate aggregate statistics for each group. List the number of books each author wrote (or cowrote). See Figure 5.3 for the result.
COUNT(*) AS "num_books"
GROUP BY au_id;
Figure 5.3 Result of Listing 5.3
Course Project - Exercise