Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

summing up fields from access arranged by date....

okay i have the following MS Access database table:


table name: order_items
fields:
  Field Name        Data Type
  ----------        ---------
  id                AutoNumber
  frn_order_id      Number
  frn_product_ID    Text
  quantity          Number
  price             Number (format is "Currency")
  dateoforder       Date/Time  
  localdealer       Text


here's is what i want to do with it:


i want to be able to output the following information:



**********************************************************
Current Month: April

Dealer               |      SalesTotal          
-------------               ----------          
d001                         $1504.15          
d002                         $1104.19          
d003                         $1042.34          
d004                         $1704.88          
d005                         $1796.01          
.                            .
.                            .
.                    .
**********************************************************


where "Dealer" is the value of the "localdealer" field, and "SalesTotal" is the SUM of the values in the "price" field for that corresponding dealer.
and also the records should be organized by month (i.e "Current Month")
by using the "dateoforder" field.
(If it's easier to list the month as 04/02, that's okay)  



and also need to output this....

*****************************************************
ProdID   Quant      Price      Date                STotal
------   -----      -----      ----                ------
101        2        $1.00      4/07/02 5:00:32 PM  $2.00
107        5        $6.25      4/09/02 5:00:32 PM  $31.25
107        1        $10.25     4/11/02 5:00:32 PM  $10.25
.          .        .          .                   .
.          .        .          .                   .
.          .        .          .                   .
---------------------------------------------------------                                     (TOTAL)

**********************************************************

where "ProdID" is the value of the "frn_product_ID" field, "Quant" is the value of the "quantity" field, "Price" is the value of the "price" field, "Date" is the value of the "dateoforder" field, "STotal" is the (quantity field x price field),
and "TOTAL" is the sum of all the "STotal" fields.


hope someone can figure this out..
0
Judy Deo
Asked:
Judy Deo
  • 5
  • 3
1 Solution
 
Judy DeoAuthor Commented:
sorry about the bad spacing in the display, i spaced it correctly in my posting but showed up different. still is readable though.
0
 
ndintenfassCommented:
For the first one, you should be able to do this in SQL.  Your CFQUERY would look something like:


SELECT localdealer,sum(price*quantity) as SalesTotal
FROM order_items
WHERE month(dateoforder) = #month(now())#
GROUP BY localdealer


You can then just build a simple HTML table using CFOUTPUT.  Do you need help with that part of it?

Or, if you need all months, but want to group by month, you could do something like:

SELECT localdealer,year(dateoforder) as year,month(dateoforder) as month,sum(price*quantity) as SalesTotal
FROM order_items
GROUP BY localdealer,year(dateoforder),month(dateoforder)
ORDER BY year(dateoforder) desc, month(dateoforder) desc

Then, use the GROUP attribute on your CFOUTPUT on the month column -- you can then output a report for each month per dealer.

Make sense?

As for the second thing -- you can either do the STotal sum in your SQL (similar to above), or just do the math as you render your output in CF.  You can add up the TOTAL as you loop over the records.  It might look something like:

<cfquery name="getOrders" datasource="YourDSN">
SELECT frn_product_id,quantity, price,dateoforder
FROM order_items
</cfquery>

<table border=1>
<tr>
<td>ProdID</td>
<td>Quant</td>  
<td>Price</td>
<td>Date</td>          
<td>STotal</td>
</tr>
<cfset total = 0>
<cfoutput query="getOrders">
<tr>
<td>#frn_product_id#</td>
<td>#quantity#</td>  
<td>#dollarFormat(price)#</td>
<td>#dateFormat(dateoforder,"m/dd/yy")# #timeFormat(dateoforder,"h:mm:ss tt")#</td>  
<cfset stotal = price * quantity>
<cfset total = total + stotal>      
<td>#dollarFormat(stotal)#</td>
</tr>
</cfoutput>
<tr>
<td colspan="4"></td>
<cfoutput><td>#dollarFormat(Total)#</td></cfoutput>
</tr>
</table>
0
 
Judy DeoAuthor Commented:
did you mean to say "use the GROUP attribute on your CFOUTPUT on the localdealer column - you can then output....?

when i group on the month column in the cfoutput,
it only displays one record for a certain month.

**********************************************
"Or, if you need all months, but want to group by month, you could do something like:

SELECT localdealer,year(dateoforder) as year,month(dateoforder) as month,sum(price*quantity) as SalesTotal
FROM order_items
GROUP BY localdealer,year(dateoforder),month(dateoforder)
ORDER BY year(dateoforder) desc, month(dateoforder) desc

Then, use the GROUP attribute on your CFOUTPUT on the month column -- you can then output a report for
each month per dealer."
**********************************************
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ndintenfassCommented:
It depends on how you want to display things.

Also, when using CFOUTPUT with the GROUP attribute you need to do a nested CFOUTPUT for the things you want output under each group.  It looks something like this:

<cfoutput group="month" query="yourQuery">
#month# #year#
<ul>
<cfoutput>
<li>#localdealer# - #SalesTotal#
</cfoutput>
</ul>
</cfoutput>

Is that what you want??



0
 
Judy DeoAuthor Commented:
the code you just pasted give this as output:

Dealer Sales Total
4 2002
d005 $43.50
4 2002
d010 $99.00
4 2002
d014 $33.00
4 2002
d016 $132.00


this is what i want to get as output:

Dealer Sales Total
4 2002
d005 $43.50
d010 $99.00
d014 $33.00
d016 $132.00


and if there were multiple months, it should output like
this:

4 2002
d005 $43.50
d010 $99.00
d014 $33.00
d016 $132.00

5 2002
d005 $28.50
d010 $128.00
d014 $44.00
d016 $199.00

.
.
.
0
 
ndintenfassCommented:
I am confused then.  I built a little sample table that I think mimics your data.  My sample table looks like this:

DATEOFORDER FRN_ORDER_ID FRN_PRODUCT_ID ID LOCALDEALER PRICE QUANTITY
2002-01-01 00:00:00  3  101  1  d001  5.0000  2  
2002-01-05 00:00:00  4  102  2  d001  2.0000  1  
2001-04-01 00:00:00  5  103  3  d002  4.0000  3  
2002-03-01 00:00:00  6  104  4  d002  9.0000  1  
2002-04-15 00:00:00  7  105  5  d002  9.0000  1  
2002-04-01 00:00:00  8  106  6  d001  9.0000  4  


When I run the query:

SELECT localdealer,year(dateoforder) as year,month(dateoforder) as month,sum(price*quantity) as SalesTotal
FROM order_items
GROUP BY localdealer,year(dateoforder),month(dateoforder)
ORDER BY year(dateoforder) desc, month(dateoforder) desc


And then use this code:

<cfoutput group="month" query="getOrders">
#month# #year#
<ul>
<cfoutput>
<li>#localdealer# - #SalesTotal#
</cfoutput>
</ul>
</cfoutput>

I get this output:

4 2002
d001 - 36.0000
d002 - 9.0000
3 2002
d002 - 9.0000
1 2002
d001 - 12.0000
4 2001
d002 - 12.0000

Perhaps I need to see more of your code to know why we are getting different behaviors.


0
 
Judy DeoAuthor Commented:
i made a syntax mistake. it works now. thanks.
0
 
Judy DeoAuthor Commented:
ndintenfass, please see my new post with the same title. it's about the same question i asked but with a change.
thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now