I'm running a query to generate a histogram from some numeric columns in a table. Here's the query:
SELECT
FLOOR((stops.stop_duration/:downtimeDivisor)/:bucketWidth)*:bucketWidth AS downtime,
COUNT(*) AS count
FROM stop_history AS stops
WHERE stops.downtime_start BETWEEN :startDate AND :endDate
AND (stops.first_fault NOT IN {hiddenFaults} OR :excludeHidden=0)
GROUP BY FLOOR((stops.stop_duration/:downtimeDivisor)/:bucketWidth)*:bucketWidth
ORDER BY FLOOR((stops.stop_duration/:downtimeDivisor)/:bucketWidth)*:bucketWidth
And the parameters are defined as such:
startDate
= 'May 1, 2019'endDate
= 'June 20, 2019'bucketWidth
= 0.5downtimeDivisor
= 3600.0hiddenFaults
evaluates to a list of stringsexcludeHidden
= false
I've used these types of parameters many times before in the same way, so I doubt they're the source of the problem.
When I run the query, I get this error in Ignition:
com.microsoft.sqlserver.jdbc.SQLServerException: Column 'stop_history.stop_duration' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I'm not trying to do a select on that column anywhere in the query, so I'm very confused.
However, if I run the exact same query (replacing the parameters with variables and the {hiddenFaults}
with a hardcoded list) in SQL Server Management Studio, it runs without any issues.
If I add stop_history.stop_duration
to the GROUP BY
clause, I get the error:
The multi-part identifier "stop_history.stop_duration" could not be bound.
And if I add stops.stop_duration
to the GROUP BY
clause, the query runs, but the data is grouped entirely wrong.
Is Ignition doing something I'm not aware of or is it somehow running the query differently than SQL Management Studio does?