how do you get the top five event codes in the last month with the historian?
I can get it from the transaction group. I don’t know how to get it from the historian.
SELECT Top 40 myCode, sum(myQuantity) as Quantity, count(myCode) as myCode_Count
FROM myTable
where ( t_stamp > DATEADD(minute, -5000, GETDATE()))
Group by myCode
order by sum(myQuantity) DESC;
Yes, I recommend the view() expression function from my free Simulation Aids module. It supports filtering and grouping and pivoting in a Pseudo-SQL format.
I need to get by without adding a module or resource if possible.
I see how to get the dataset from the historian with the system.tag.queryTagHistory
I don’t know how to query it though.
Is there some way to point the queries at the dataset and use named queries on it?
So far, I only can do queries on the transaction group tables.
I put the name of the table made by the transaction group in the from section, and I am able to query.
That is precisely what my view() function does. Nothing else that I've seen anywhere in Ignition will do this for you. Your alternative is to script the grouping and pivoting yourself.
So I presume you’ve figured out how to get your fault code history using a tag history binding or a named query binding to get one row per event, yielding a t_stamp column and the fault code column. Also presumably limited to the time period of interest. Hook such a binding up to a custom dataset property on a container or a table.
Then, on the table’s data property, place this expression binding:
view("Selec faultCode, len(faultCode) As Qty Group By faultCode Order By -Qty",
{Root Container.path.to.table.customProp})
Put your actual column and property names in that.
Simulation Aids is on my local.
The datasets I need to work on are on production, and I am not authorized to add modules to the gateway or add resources from exchange to the project.
I didn't know Partition By was a thing in queries.
I also need to read up on lead and lag.
This thread was linked early in this thread, and I like your post on it.
I think I need to implement that kind of query.
I don't think a tag historian binding has "partition by" functionality.
I think for this fault code , I have to use the transaction group since I can't add the resource that you made.
I understand this. Adding and upgrading modules can be disruptive--if the module has any elements in Vision Client and/or Designer scopes, those scopes are forced to restart. Gateway scripting also restarts, similar to project saves.
I recommend you encourage adoption of my Simulation Aids module at some point though, properly coordinated with production. I consider it essential, which is why I made it free.