11

Need help with a SOQL Query. We are trying to pull our highest sales records by month and user. Looking to see something like: "John Doe 100 Sales May 2014. Currently I am getting the calendar month, but not the year. Below is what I have currently, any suggestions are appreciated!

SELECT Count(Id), Sold_By__r.Name, calendar_month(Sold_By_Date__c) 
FROM Case 
WHERE Status = 'Sold' 
AND Sold_By__c !='005U0000000aL0BIAU' 
AND Sold_By__c !=''  
GROUP BY Sold_By__r.Name, calendar_month(Sold_By_Date__c) 
ORDER BY Count(Id) DESC 
LIMIT 10

1 Answer 1

21

You can also use the CALENDAR_YEAR(Sold_By_Date__c) to pull out the year part of the data

SELECT Count(Id), Sold_By__r.Name, calendar_year(Sold_By_Date__c), calendar_month(Sold_By_Date__c) 
FROM Case 
WHERE Status = 'Sold' 
AND Sold_By__c !='005U0000000aL0BIAU' 
AND Sold_By__c !=''  
GROUP BY Sold_By__r.Name, calendar_year(Sold_By_Date__c), calendar_month(Sold_By_Date__c) 
ORDER BY Count(Id) DESC 
LIMIT 10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .