If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Grouping by Month

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-17-10, 09:08
pamam88 pamam88 is offline
Registered User
 
Join Date: Jun 2010
Posts: 2
Grouping by Month

hi all, i am new to SQL and trying to pick up the pieces urgently

any urgent help will be appreciated

Where MEMBERS.ID links to SALES.MemberID write SQL queries to achieve an output dexcribed by the following

2xtables

MEMBERS
ID int, not null
FirstName text
LastName text
EmailAddress text

SALES
ID int, not null
MemberID int
PurchaseDate datetime
Description text
Quantity int
Amount money

and the question
6) Return a sum of sales by month which can be matched to a member sale.

thus far i have the query though its not what i am after
SELECT SALES.MemberID, MEMBERS.FirstName, MEMBERS.LastName, Sum(SALES.Amount) AS SumOfAmount
FROM MEMBERS INNER JOIN SALES ON MEMBERS.ID = SALES.MemberID
GROUP BY SALES.MemberID, MEMBERS.FirstName, MEMBERS.LastName;

which gives the total for each MemberID
but i am assuming based on the question i am asked to separate these figures into related month columns
Reply With Quote
  #2 (permalink)  
Old 06-17-10, 11:15
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
First attempt looks good and you are on the right track. So you have to pull the month out of the date column.
Reply With Quote
  #3 (permalink)  
Old 06-17-10, 16:51
pamam88 pamam88 is offline
Registered User
 
Join Date: Jun 2010
Posts: 2
sorry

could you direct me a little bit further. sort of stuck

been told to use the MONTH(PurchaseDate) in my query but lost on aything further than this.

any direction would be great
Reply With Quote
  #4 (permalink)  
Old 06-18-10, 07:45
sathkum2281 sathkum2281 is offline
Registered User
 
Join Date: Jun 2010
Posts: 4
can try these queries,

1)select m.firstname,m.lastname,month(s.purchasedate) as month_purchase,sum(s.Amount) as tot_amount from MEMBERS m join SALES s ON (m.ID=s.MemberID) group by m.ID,month_purchase

2)select month(purchasedate) as month_purchase,sum(Amount) as tot_amount from SALES group by month_purchase
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On