« first day (1755 days earlier)      last day (367 days later) » 

6:24 AM
@Martin you could have extended that into an answer. I realize I missed the with option I have after the openjson as that would have eliminated the need for json_value in the projection.
 
 
1 hour later…
7:29 AM
Well, I am not sure I would have find time to modify those queries. (And after all, the OP could have looked at them and try to modify them.)
In any case, there is no doubt that the query you posted is much better than what I would be able to put together.
Although now I found that I looked at a statistics per-tag in the past - so perhaps there would not be too much to modify:
 
Don't under estimate what you've already put together here and there.
 
8:13 AM
BTW one of the things I plan to learn when I have a bit more time is how to use PIVOT - I have mentioned that here before: chat.meta.stackexchange.com/transcript/1223/2023/2/3
I see that your query uses pivot in one place.
 
 
2 hours later…
10:41 AM
I struggle a lot with pivot. I never seem to be able to get the syntax right on the first try and always have to refer back to my simple example. And when I have overcome the syntax errors, the results are not correct. Either it groups on the wrong field or it doesn't like the aggregate function I use. It is not intuitive at all.
I might be spoiled by MS Access that does have a pivot statement but it can take rows from a table as column headers. So it is totally dynamic. Not the case in SQL Server.
 

« first day (1755 days earlier)      last day (367 days later) »