January 2019
Beginner
556 pages
14h 19m
English
Databases are often used as a data source for any kind of reporting. In reports, it's quite common to display subtotals, totals, and grand totals that summarize the data rows in the same table, implying, in fact, grouping, and aggregation. Consider the following report, which displays the number of advertisements by car make and quarter, and displays the totals for each quarter (aggregating all makes), and the grand total. Here's how to select the data for the report:
car_portal=> SELECT to_char(advertisement_date, 'YYYY-Q') as quarter, make, count(*) FROM advertisement a INNER JOIN car c ON a.car_id = c.car_id INNER JOIN car_model m ON m.car_model_id = c.car_model_id GROUP BY quarter, make; quarter | make | count ...
Read now
Unlock full access