Statement with Joins and Aggregate Count
I have 3 tables: Agents, Teams, and Items
Any help would be greatly appreciated.
Agents { AgentReference, AgentName, TeamReference } Teams { TeamReference, TeamName } Items { ApplicationReference, TeamReference, DateDeleted }I want to create a query that gives me a List by each Agent of
{ AgentReference, TeamReference, COUNT(ApplicationReferences)}
Any help would be greatly appreciated.
Comments
Any visualisation would help. What is your end goal? Do you want a SQL query or do you need LINQ? Query Syntax or Method Syntax? Do you want to edit data, export or just view?
Yes, they are table related.
Yes, TeamReference is the FKey in Agents and Items table.
TeamReference is the Primary Key in Teams table.
Team does not have a self-reference.
I'm trying to get a count of all ApplicationReferences that belong to the Agent, along with the Agents TeamReference.
DateDeleted must equal a null for the application to get counted. Sorry I missed this one.
The goal to provide a count of application from each Agent that can be rolled up to for the Team total
If you have a better idea on how to solution this problem, please let me know.
Thank you again.
Table layout: Query: You may also have foreign keys in database: Which makes joining somewhat easier: