codershangout.co.uk


Web Design Forums | Web Design & Development Help Forum

order totals by month

You can discuss MySQL and other databases here. If your having problems, just post here and someone will help you.

order totals by month

Postby puma2 » Sat Jun 11, 2011 9:38 am

I have a table of orders on an e-commerce site and i'd like to pull out the total value of orders broken down month by month

The database looks like:
order_id | customer_id | order_date | total | paid

How would i do that in SQL?
puma2
 
Posts: 3
Joined: Sun May 22, 2011 1:42 pm

Re: order totals by month

Postby hboss » Tue Oct 04, 2011 5:38 am

CurrentMonth = Month(CurrentDate)
CurrentYear = Year(CurrentDate)

SQL = "SELECT Spent, MONTH(Date) AS InvMonth, YEAR(Date) As InvYear FROM Invoices WHERE YEAR(Date) = '" & CurrentYear & "' AND MONTH(Date) = '" & CurrentMonth & "'"
RecordSet.Open SQL, Connection, adOpenStatic, adLockOptimistic, adCmdText
Do Until RecordSet.EOF
MTotal(i) = MTotal(i) + RecordSet.Fields("Spent")
RecordSet.MoveNext
Loop
RecordSet.Close
hboss
 
Posts: 6
Joined: Wed Sep 28, 2011 10:58 am

Re: order totals by month

Postby hboss » Tue Oct 04, 2011 5:39 am

CurrentMonth = Month(CurrentDate)
CurrentYear = Year(CurrentDate)

SQL = "SELECT Spent, MONTH(Date) AS InvMonth, YEAR(Date) As InvYear FROM Invoices WHERE YEAR(Date) = '" & CurrentYear & "' AND MONTH(Date) = '" & CurrentMonth & "'"
RecordSet.Open SQL, Connection, adOpenStatic, adLockOptimistic, adCmdText
Do Until RecordSet.EOF
MTotal(i) = MTotal(i) + RecordSet.Fields("Spent")
RecordSet.MoveNext
Loop
RecordSet.Close
hboss
 
Posts: 6
Joined: Wed Sep 28, 2011 10:58 am


Return to Databases

Who is online

Users browsing this forum: No registered users and 0 guests

cron