I am trying to create a query that provides me with the total number of Agents (AgentID) for each OfficeID. If someone could please guide me in the right direction, also if there are resources that give you a bunch of examples of different types of queries that would be useful for the future!
My issue right now is the syntax. I'm not sure where things need to go in order to get the desired output above.
Here's what I have as of now:
Tables OFFICE and AGENT:
CREATE TABLE OFFICE
(
OfficeID NVARCHAR(5) UNIQUE,
OfficeAddress NVARCHAR(18) NOT NULL,
PRIMARY KEY(OfficeID)
)
GO
CREATE TABLE AGENT
(
AgentID NVARCHAR(8) UNIQUE,
OfficeID NVARCHAR(5) NOT NULL,
AgentType NVARCHAR(9) NOT NULL,
AgentFName NVARCHAR(10) NOT NULL,
PRIMARY KEY (AgentId),
FOREIGN KEY (OfficeID) REFERENCES OFFICE
ON DELETE CASCADE
ON UPDATE CASCADE
)
GO
Query:
SELECT
OFFICE.OfficeID
FROM
OFFICE,
(SELECT COUNT(AgentID)
FROM AGENT, OFFICE
WHERE OFFICE.OfficeID = AGENT.OfficeID
GROUP BY AGENT.OfficeID)
ORDER BY
OFFICE.OfficeID
JOINsyntax in the ANSI-92 SQL Standard (more than 25 years ago) and its use is discouraged