expressions and summarization william klingelsmith
TRANSCRIPT
![Page 1: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/1.jpg)
Expressions and SummarizationWilliam Klingelsmith
![Page 2: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/2.jpg)
Expressions• Expressions perform calculations row-wise and derive new
fields from existing fields in queries• Expression syntax will always resemble:• Expression Name: <Expression Body>
• Expressions have an advantage over storing items in a field in your tables• Smaller database size• Drawback: if the expression is very complex, query run time will
be longer
![Page 3: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/3.jpg)
Expressions• In the right-most blank in your field list inside of your query
design, click in the field row.• Expressions can be entered directly into the blank by hand or
the expression builder can be used (Builder button on the design tab)
![Page 4: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/4.jpg)
Expressions• Within builder, you have access to built-in functions in
access(SUM, MIN, MAX, etc.)• Most of the time, your expressions will be constructed using
basic mathematical operators• Expanding the dropdown next to the name of your database
will let you access tables(and fields), queries, forms, and reports for use in your expressions
![Page 5: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/5.jpg)
Expressions• Let’s create a few expressions:• Calculate the number of albums sold• Calculate the price of an album with tax• Projected next year sales
• (NumberofAlbumsSold +1000) * 0.50• Write an expression to determine whether an album is expensive
(Over $10 in price)• Write an expression to display only the year that albums were
released
![Page 6: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/6.jpg)
Summarization• Expressions are very powerful, but as previously stated they
work row-wise• What if we wanted to find an average price of albums by genre or
the total number of albums sold in each genre?
![Page 7: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/7.jpg)
Summarization• By using the Total Row in your design, these types of queries
can be created.• To activate the total row in your query design, click the Totals
button located on the Design tab(Giant Sigma).
![Page 8: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/8.jpg)
Summarization• Create a new query which contains the tables (Albums, Sales,
and Genre)• Populate the query using the fields (GenreName,
SalesinDollars, and AlbumPrice)• Turn on the Totals Row mechanism
![Page 9: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/9.jpg)
Summarization• Notice that a new row is created in your query design. • We will set up summaries of data by using this row.
• All fields have ‘Group By’ as their default option. This will need to be changed depending on what fields you wish to summarize your queries by.
![Page 10: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/10.jpg)
Summarization• For this example, we will using the following total row options• GenreName: Group By• SalesinDollars: Average• Album Price: Average
![Page 11: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/11.jpg)
Summarization• When you run the query, notice that there are fewer results
than before.• There are only unique entries for the GenreName field under
which we placed the ‘Group By’ clause• What is going on here?
![Page 12: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/12.jpg)
Summarization
Query2GenreName SalesInDollars AlbumPrice
EBM $1,265,000.00 $11.00
EBM $7,992,000.00 $9.99
Notice that when the Totals Row is turned off there are two results for EBM, but when it’s on we only get one results with
EBM
The Total Row will compact the results of a query by the field with the Group By clause into bins
Functions under fields in these bins are performed
![Page 13: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/13.jpg)
Summarization• Notice that each field using a function in the totals row now
has prepended to it the name of the function• AvgOfAlbumPrice
• These fields can be aliased to have a more-specific name by using expression syntax• Average of Album Price: AlbumPrice
![Page 14: Expressions and Summarization William Klingelsmith](https://reader031.vdocument.in/reader031/viewer/2022020106/56649ce45503460f949b11f3/html5/thumbnails/14.jpg)
Totals Row Examples• Create a query to find the number of Albums in each genre• You should get 12 results
• Find the highest priced album in each genre• You should get 12 results