Hello guys i need help im stuck dont bully me for this i know it can be easy for you but im just bad at thinking lol 😀 read few times the manual on w3school and etc but still dont understand this nonsense
i need and sql query which can count how many real estate objects agent has , the database that im currently working on sql is about real estate its in lithuanian , the task is to list agent name(AgVardas), surname(AgPavardė) , phone (AgTelefonas), agency name(AgentūrosPavadinimas), and real estate objects(Nekilnojamuobektuskaicius) that agent has. The names in () these brackets are original values in my native language (Lithuanian)
i have to use the query with inner join
because its in other tables
the databases https://imgur.com/a/qa1JUWt
the code query i have tried is
SELECT `AgPavardė`,`AgVardas`,`AgTelefonas`,`AgentūrosPavadinimas` FROM `agentai` INNER JOIN agentūros ON agentūros.AgentūrosNr = agentai.AgentūrosNr
it works and all but i need to add another column to show me Real estate objects that agent owns(number)
example how it should look
So the question is how to do so?
Advertisement
Answer
You can replace the column and table names in the below query with your Lithuanian names and it should work.
SELECT agent.Agent_Name, agent.Agent_Surname, agent.Agent_Phone , agency.Agency_name, COUNT(ad.ad_number) as Real_Estate_Objects FROM tbl_agent agent INNER JOIN tbl_agency agency ON agency.agency_number = agent.agency_number INNER JOIN tbl_ads ad ON ad.agent_number = agent.agent_number GROUP BY agent.Agent_Name, agent.Agent_Surname, agent.Agent_Phone , agency.Agency_name