You need to sign in to do that
Don't have an account?

SQL query for salesforce objects
Hi,
I have a Contact and Opportunity(Donations) objects.
Opportunity is child obj for Contact.
In our case, for one contact there may be several opportunity( donation) records.
Close date and Amount are two fields in opportunity.
How to query for a condition in sql, most recent close date and most recent amount ? for a given date range and given amount range.
select name,max(date),amount
from donations
where closedate> '2011-3-4' and closedate < '2012-2-4' and amount>10 and amount<100
group by name
but it throws me an error on amount field as it is not in aggregate function.
how to modify this query such that for each contact record, it pulls donation's recent close date and recent amount. ( Consider for 1 contact we have 10 donations. so we need to pull 10th donation details.)
select name,max(date),amount
from donations
where closedate> '2011-3-4' and closedate < '2012-2-4' and amount>10 and amount<100
group by name,amount
you need to group or aggregate every field you requested in the query or it fails.
Hi,
Did my answer helped you?