Information Technology Topic

Database Reports

  1. Read notes
  2. Flashcards
  3. Quiz
  4. Confident

Study focus - 3 things

  1. A report presents data from a table or query in a layout for people to read, with a title, column headings, one detail line for each record, and a header and footer for each group
  2. Sort first and group second: records must be sorted by the group field, and the group footer then shows summary features such as count, sum and average, with grand totals at the end
  3. Preview a report on screen to check it, print it for a paper copy, or save it to a file to edit or send, and always check that the group figures add up to the grand total

Section 1What a report is

A report presents the data from a table or query in a layout that people can read without knowing how the database works. Reports are laid out for printing, but you can look at them on screen first. A report can be a table of records, a chart, labels or a form letter. Here's the trick: tables and queries are for working with data, and reports are for showing it. We use a school in Portmore that records the points students win on sports day. ENTRY (EntryID, Name, House, Event, Points): 1, Andre Reid, Blue, Relay, 10; 2, Shanice Clarke, Gold, 100m, 8; 3, Kemar Lewis, Green, Long jump, 6; 4, Tanya Gordon, Red, 100m, 9; 5, Omar Brown, Blue, Shot put, 7; 6, Marcia Francis, Gold, Relay, 10; 7, Devon Campbell, Red, Shot put, 5; 8, Keisha Hall, Green, 100m, 8; 9, Ryan Thompson, Blue, 100m, 4; 10, Alicia Morgan, Gold, Long jump, 6; 11, Jermaine Wright, Red, Relay, 7; 12, Nadine Brown, Green, Relay, 9; 13, Dwayne Francis, Blue, Long jump, 3; 14, Kerry-Ann Lewis, Red, Long jump, 7. There are 14 records and the four houses are Blue, Gold, Green and Red.

Section 2Start from a query

A report is best built from a query that already holds the records you want in the order you want. In the query you choose the fields to show (Name, House, Event, Points), filter the records with criteria, and add calculated fields if you need them. For example, a query for 'Red house, Points of 7 or more' picks out Tanya Gordon (9), Jermaine Wright (7) and Kerry-Ann Lewis (7). The report then takes those records and handles the layout, the grouping and the summaries. Sorting is best set in the query, and the report's sorting and grouping settings then build on it.

Section 3The parts of a report

A report is arranged in sections. Report header: the title, once at the start (SPORTS DAY POINTS). Page header: the column headings, at the top of every page. Group header: a heading before each group, such as House: Blue. Detail: one line for each record. Group footer: the summary figures for that group. Report footer: the grand totals, once at the end. Page footer: the page number and date at the bottom of every page. Not every report needs every section.

Section 4Sorting and grouping

Sorting puts the records in order. Grouping gathers records that have the same value in a field under a header and footer. A new group starts for each different value. Sort first, then group. A new group starts every time the value in the group field changes, so the records must be in order by that field. Some packages do this sort for you when you set up a group, but do not count on it. If the records are not sorted by the group field, a new group starts every time the House changes. In the stored order of the ENTRY table that makes 14 groups of one record each, which is useless. Sort by House (A to Z), then by Points (highest first), then by Name (A to Z) to break ties. The groups come out in the order Blue, Gold, Green, Red, and the Blue group reads Andre Reid 10, Omar Brown 7, Ryan Thompson 4 and Dwayne Francis 3. Text fields can also be grouped by first letter, and a counter can number the detail lines 1, 2, 3 and so on.

Section 5Summary features: count, sum and average

A summary feature turns many records into one figure. Count is how many records, sum is the total of a field, average is the sum divided by the count, and minimum and maximum give the lowest and highest. Put them in the group footer for each group, and in the report footer for the whole report. For the points: Blue has count 4, sum 24 and average 24 / 4 = 6. Gold has 3, 24 and 8. Green has 3, 23 and 23 / 3 = 7.67, rounded to 2 decimal places. Red has 4, 28 and 7. The grand totals are count 14, sum 99 and average 99 / 14 = 7.07. Red has the highest total (28) and Gold the highest average (8). Watch out: the grand average is not the average of the four house averages. That gives 7.17, because the houses have different numbers of records. If your package has no average, divide the sum by the count.

Section 6Output: screen, printer or file

A finished report can go to three places. Screen: a preview. Use it to check the layout and the figures before anything else, and it costs no paper. Printer: a paper copy, for example a points sheet for the school notice board. File: the report is saved as a document, such as a text document or a spreadsheet, so it can be sent by email or edited later. The data and layout are the same each time. You choose the output by what the reader needs, so check on screen first, and then print or save.

Section 7Checking a report

Check the report before you hand it in. The group counts must add up to the total number of records: 4 + 3 + 3 + 4 = 14. The group sums must add up to the grand total: 24 + 24 + 23 + 28 = 99. Check the order. Each group should be in the right sequence, and inside a group the records should follow your sort. In the Red group the 7-point tie is broken by name, so Jermaine Wright comes before Kerry-Ann Lewis. Test one average with a calculator. Check that every heading and label is clear, and that the report includes only the records the query was meant to pick out. Grouping the same data by Event instead gives four groups: 100m (4 records, sum 29, average 7.25), Long jump (4, 22, 5.5), Relay (4, 36, 9) and Shot put (2, 12, 6). The sums again add up to 99 and the counts to 14.

Examples

ENTRY (EntryID, Name, House, Event, Points): 1, Andre Reid, Blue, Relay, 10; 2, Shanice Clarke, Gold, 100m, 8; 3, Kemar Lewis, Green, Long jump, 6; 4, Tanya Gordon, Red, 100m, 9; 5, Omar Brown, Blue, Shot put, 7; 6, Marcia Francis, Gold, Relay, 10; 7, Devon Campbell, Red, Shot put, 5; 8, Keisha Hall, Green, 100m, 8; 9, Ryan Thompson, Blue, 100m, 4; 10, Alicia Morgan, Gold, Long jump, 6; 11, Jermaine Wright, Red, Relay, 7; 12, Nadine Brown, Green, Relay, 9; 13, Dwayne Francis, Blue, Long jump, 3; 14, Kerry-Ann Lewis, Red, Long jump, 7. There are 14 records and the four houses are Blue, Gold, Green and Red. A report is built from the ENTRY table. It is sorted by House (A to Z), then by Points (highest first), and grouped by House. (a) State the order of the group sections and name the first record in the Gold group. (b) State the count, sum and average shown in the group footer for Gold. (c) The head teacher wants a copy for the school notice board and a copy that the sports teacher can edit. State the output to use for each.

(a) Sorting by House A to Z puts the groups in the order Blue, Gold, Green, Red. The Gold records are Marcia Francis (10), Shanice Clarke (8) and Alicia Morgan (6). With the highest Points first, the first record in the Gold group is Marcia Francis. (b) Gold has 3 records, so the count is 3. The sum is 10 + 8 + 6 = 24. The average is the sum divided by the count, 24 / 3 = 8. (c) The notice board needs a paper copy, so send the report to the printer. The sports teacher wants to edit it, so save the report to a file, such as a text document or a spreadsheet.

ENTRY (EntryID, Name, House, Event, Points): 1, Andre Reid, Blue, Relay, 10; 2, Shanice Clarke, Gold, 100m, 8; 3, Kemar Lewis, Green, Long jump, 6; 4, Tanya Gordon, Red, 100m, 9; 5, Omar Brown, Blue, Shot put, 7; 6, Marcia Francis, Gold, Relay, 10; 7, Devon Campbell, Red, Shot put, 5; 8, Keisha Hall, Green, 100m, 8; 9, Ryan Thompson, Blue, 100m, 4; 10, Alicia Morgan, Gold, Long jump, 6; 11, Jermaine Wright, Red, Relay, 7; 12, Nadine Brown, Green, Relay, 9; 13, Dwayne Francis, Blue, Long jump, 3; 14, Kerry-Ann Lewis, Red, Long jump, 7. There are 14 records and the four houses are Blue, Gold, Green and Red. A second report groups the same data by Event. It is sorted by Event (A to Z), then by Points (highest first), then by Name (A to Z). (a) State the order of the group sections. (b) Calculate the count, sum and average for each event group. (c) Check the figures against the whole table. (d) State which event has the highest average and name the first record in that group.

(a) Event sorted A to Z gives 100m, Long jump, Relay, Shot put, which is 4 groups. (b) 100m: Shanice Clarke 8, Tanya Gordon 9, Keisha Hall 8 and Ryan Thompson 4. Count 4, sum 29, average 29 / 4 = 7.25. Long jump: Kemar Lewis 6, Alicia Morgan 6, Dwayne Francis 3 and Kerry-Ann Lewis 7. Count 4, sum 22, average 22 / 4 = 5.5. Relay: Andre Reid 10, Marcia Francis 10, Nadine Brown 9 and Jermaine Wright 7. Count 4, sum 36, average 36 / 4 = 9. Shot put: Omar Brown 7 and Devon Campbell 5. Count 2, sum 12, average 12 / 2 = 6. (c) The counts are 4 + 4 + 4 + 2 = 14, which is every record. The sums are 29 + 22 + 36 + 12 = 99, which matches the grand total of 99. (d) Relay has the highest average, 9. Andre Reid and Marcia Francis both have 10 points. The tie is broken by Name A to Z, so Andre Reid is the first record in the Relay group.

Now let's water it

Session runs notes to flashcards to quiz back-to-back.

Where this comes from