RelationalDBDesign
SiteMap
Business Rules
Cursors Views
Database Creation
SQL Monitoring
Database Web Apps
Data Manipulation
Access Features
Tables Queries
Select Data
«Prev
Next»
Queries Cursors Views
SQL-Query Basics
Executing Queries
Batch Queries
System Catalogs
Writing Logic Queries
Dynamic SQL Statements
SQL Server Basics
Selecting Data
Data Overview
Retrieving Data Multiple Tables
Multiple Table Retrieval
Alternate Queries Aliases
Construct Union Queries
Additional Keywords Queries
Define Aggregate Queries
Aggregated Data Queries
Describe Write Subqueries
Using Subqueries - Exercise
Selecting Data Conclusion
Advanced Queries
Inserting Transact SQL Data
Updating Transact-SQL Data
Deleting Data
SQL Statement Punctuation
Insert Values from other Table
Update Values from other Table
Different Datatypes
Subquery Statements
Indexing Query Strategies
Full Text Searching
Full Text Searching
Full Text Searching Components
Defining Full Text Indexes
Implement Full Text Search
Full Text Searching
SQL Server 2025 Cursors
When to Use SQL Server Cursor
SQL Server Cursor Types-Options
LOCAL-GLOBAL Cursor Scope
Cursor Variables - References
How to Declare Cursor
OPEN Cursor in SQL Server
FETCH | Cursor Navigation
CLOSE Cursor SQL Server 2025
DEALLOCATE - Cursor Cleanup
How Cursors Respond to Data Changes
SQL Cursors Module Review
Aggregate Data - Exercise
Creating an Aggregate Query
Objective:
Practice creating an aggregate query.
Exercise Scoring
This exercise is worth a total of 30 points. You will receive up to 30 points for accurately creating the aggregate query as described in the instructions.
Instructions
Consider this to be the data in the Sales table to produce your aggregate query:
Division
SaleDate
SaleAmount
East
01/01/2025
100000
East
01/05/2025
5000
East
02/02/2025
25000
West
01/10/2025
60000
North
05/05/2025
52000
North
04/13/2025
30000
South
01/03/2025
25000
South
01/22/2025
50000
Use Transact-SQL to create a query containing an aggregate expression that produces a summary result set that looks exactly like the following:
Division
JanuarySales
East
105000
South
75000
West
60000
Make sure to note the column names returned in the result set, as you will need to use aliasing. Also note that the JanuarySales column should only contain sales for the month of January.
Hint: to test whether a SaleDate value falls in a specific month, use the T-SQL
MONTH
function, like this:
MONTH(datecolumn)
This function returns the numeric month of the date specified by
datecolumn
. You can use this function in the
WHERE
clause to test that the value returned is 1, for January.
Take your time and think this one through!
Submitting the Exercise
Type or paste your Transact-SQL statement into the text box below, then click
Submit
to submit it and view a results page.