Author |
Message |
cpresk
Newbie
Joined: 18 Jan 2017
Online Status: Offline
Posts: 9
|
Posted: 27 Jan 2017 at 8:12am |
I think this will actually help me a lot with speeding up future reports. For this particular chart, I don't think I need to join any tables. I am almost illiterate when it comes to SQL, but here is what I pared this down to -
SELECT If_no_products_floored_why_not__c, Max (Date__c) as 'maxDate', Store_Name__c,
FROM Call_Report_Entry__c
It's not working and I'm guessing it's a simple syntax error, but I can't figure out what it is.
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|
Posted: 27 Jan 2017 at 8:32am |
What is the error you're getting?
-Dell
|
|
IP Logged |
|
cpresk
Newbie
Joined: 18 Jan 2017
Online Status: Offline
Posts: 9
|
Posted: 27 Jan 2017 at 9:30am |
I'm trying to attach a picture, but can't figure out how to do it! It says 'Failed to retrieve data from the database......syntax error near 'SELECT........as 'maxDate'<<<???>>>, Store_Name_c......'
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|
Posted: 27 Jan 2017 at 10:24am |
I see the issue now. Remove the comma after "Store_Name__c" in the Select part of the query.
-Dell
|
|
IP Logged |
|
cpresk
Newbie
Joined: 18 Jan 2017
Online Status: Offline
Posts: 9
|
Posted: 30 Jan 2017 at 4:35am |
GAAA!!! Now I have a new error! I'm definitely going to need to take some SQL training. Any suggestions?
Anyway, the new error says - 'Failed to retrieve data from database.
Details: 42000:[Simba][SQLEngine] (31430) Column 'datasource.If_no_products_floored_why_not_c' is neither in an aggregate function nor from the GROUP BY clause. [Database Vendor Code: 31430]
Any idea what that means?
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|
Posted: 30 Jan 2017 at 5:26am |
This one's an easy fix. When you use a summary (sum, max, etc) in a query, all of the fields that are not in a summary have to be in a Group By clause in the query. So, you'll need to change it to this:
SELECT If_no_products_floored_why_not__c, Max (Date__c) as 'maxDate', Store_Name__c
FROM Call_Report_Entry__c
GROUP BY If_no_products_floored_why_not__c, Store_Name__c
-Dell
|
|
IP Logged |
|
cpresk
Newbie
Joined: 18 Jan 2017
Online Status: Offline
Posts: 9
|
Posted: 30 Jan 2017 at 9:39am |
Getting closer...I was able to get the data in now, but I'm still getting all of the visits instead of just the most recent to each store. Do I need something else in the Max function to tell it to only include the most recent visit to each store?
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|
Posted: 30 Jan 2017 at 10:39am |
I'm pm-ing you my email address so that you can send me the report to take a look at. I think something is getting lost in translation here.
Thanks!
-Dell
|
|
IP Logged |
|
hilfy
Admin Group
Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
|
Posted: 31 Jan 2017 at 12:40pm |
Ok, you're getting the extra details because of the differences in data in If_no_products_floored_why_not__c.
You have two options for this query, depending on whether SalesForce will allow you to join to a sub-query.
Option 1 - This is faster at the database level:
SELECT cre.If_no_products_floored_why_not__c, cre.Date__c as maxDate, cre.Store_Name__c
FROM Call_Report_Entry__c as 'cre'
inner join (
Select Store_Name__c, Max(Date__c) as maxDate
from Call_Report_Entry__c
group by Store_Name__c
) as maxDates
on cre.Store_Name__c = maxDates.Store_Name__c
and cre.Date__c = maxDates.maxDate
Option 2 - If it won't left you use the subquery in a join, try this:
SELECT cre.If_no_products_floored_why_not__c, cre.Date__c as maxDate, cre.Store_Name__c
FROM Call_Report_Entry__c as 'cre'
WHERE cre.Date__c =
(
Select Max(Date__c) as maxDate
from Call_Report_Entry__c as 'tmp'
where tmp.Store_Name__c = cre.Store_Name__c
) as maxDates
-Dell
|
|
IP Logged |
|
|