Judy Deo
asked on
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..
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
. . . . .
. . . . .
. . . . .
--------------------------
**************************
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..
For the first one, you should be able to do this in SQL. Your CFQUERY would look something like:
SELECT localdealer,sum(price*quan tity) 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(dateoford er) as year,month(dateoforder) as month,sum(price*quantity) as SalesTotal
FROM order_items
GROUP BY localdealer,year(dateoford er),month( dateoforde r)
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(dateoforde r,"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>#dollarForma t(Total)#< /td></cfou tput>
</tr>
</table>
SELECT localdealer,sum(price*quan
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(dateoford
FROM order_items
GROUP BY localdealer,year(dateoford
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>#dateFormat(dateoforde
<cfset stotal = price * quantity>
<cfset total = total + stotal>
<td>#dollarFormat(stotal)#
</tr>
</cfoutput>
<tr>
<td colspan="4"></td>
<cfoutput><td>#dollarForma
</tr>
</table>
ASKER
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(dateoford er) as year,month(dateoforder) as month,sum(price*quantity) as SalesTotal
FROM order_items
GROUP BY localdealer,year(dateoford er),month( dateoforde r)
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."
************************** ********** **********
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(dateoford
FROM order_items
GROUP BY localdealer,year(dateoford
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."
**************************
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??
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??
ASKER
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
.
.
.
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
.
.
.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i made a syntax mistake. it works now. thanks.
ASKER
ndintenfass, please see my new post with the same title. it's about the same question i asked but with a change.
thanks.
thanks.
ASKER