I am in need of the SQL help. I am working with three different record types: customer, contact, and phone call. I am trying to create a customer saved search that sums up an integer field (chart pulls) on all the contacts for each customer and shows the most recent call date out of all contacts per customer.
Example:
Customer A has two contacts:
Contact A1 - 10 chart pulls; has phone call on 7/1/2013
Contact A2 - 15 chart pulls; has phone calls on 7/2/2013 and 7/3/2013
Customer B has two contacts:
Contact B1 - 15 chart pulls; has phone call on 7/3/2013
Contact B2 - 15 chart pulls; has phone calls on 7/4/2013 and 7/5/2013
Desired result:
Customer Name | Total Chart Pulls | Last Phone Call
Customer A | 25 | 7/3/2013
Customer B | 30 | 7/5/2013
If I try the following, the # of chart pulls is inflated:
Name (Group)
Contact : Chart Pulls (Sum)
Call : Date Completed (Maximum)
Result:
Customer Name | Total Chart Pulls | Last Phone Call
Customer A | 75 | 7/3/2013
Customer B | 90 | 7/5/2013
I tried to use SQL, but couldn't quite get it to work:
Name (Group)
Formula (Numeric) - SUM(DISTINCT {contact.custentity_chart_pulls_this_month})
Call : Date Completed (Maximum)
Result:
Customer Name | Total Chart Pulls | Last Phone Call
Customer A | 25 | 7/3/2013
Customer B | 15 | 7/5/2013
I need a way to SUM the chart pulls per contact per customer, while still being able to get the last phone call date.
Any ideas? Appreciate the help!