<!--- Retrieve summarized expense data from database --->
<CFQUERY NAME="GetExp" DATASOURCE="#REQUEST.DataSource#">
  SELECT 
    COUNT(*) AS ExpenseCount,
    MIN(ExpenseDate)   AS DateMin,
    MAX(ExpenseDate)   AS DateMax,
    MIN(ExpenseAmount) AS ExpenseMin,
    MAX(ExpenseAmount) AS ExpenseMax,
    SUM(ExpenseAmount) AS ExpenseSum,
    AVG(ExpenseAmount) AS ExpenseAvg
  FROM Expenses
</CFQUERY>


<HTML>
<HEAD><TITLE>Film Expenses</TITLE></HEAD>
<BODY>
<H2>Expense Overview</H2>

<!--- Output high-level expense summary --->
<CFOUTPUT>
  <B>Number of expenses logged:</B> 
    #GetExp.ExpenseCount#<BR>

  <B>Oldest expense on record:</B> 
    #LSDateFormat(GetExp.DateMin, "mmmm d, yyyy")#
    (#DateDiff("m", GetExp.DateMin, Now())# months ago)<BR>

  <B>Most recent expense on record:</B> 
    #LSDateFormat(GetExp.DateMax, "mmmm d, yyyy (dddd)")#<BR>

  <B>Smallest expense made:</B> 
    #LSCurrencyFormat(GetExp.ExpenseMin)#<BR>

  <B>Largest expense made:</B> 
    #LSCurrencyFormat(GetExp.ExpenseMax)#<BR>

  <B>Average expense amount:</B> 
    #LSCurrencyFormat(GetExp.ExpenseAvg)#<BR>

  <B>Total of all expenses to date:</B> 
    #LSCurrencyFormat(GetExp.ExpenseSum)#<BR>
</CFOUTPUT>

</BODY>
</HTML>