0

I am super new to SQL and have been working on this query and can not seem to get it to work. I need to sum the categories (how many clients are in each country and how many clients each employee has). This is what I tried to do to get the total clients in each country:

COUNT(*) TotalCount,
country.id, country.country
FROM client
INNER JOIN country
ON client.country_id = country.id
GROUP BY country.id, country.country

These are my tables:

CREATE TABLE employee(
    id INT AUTO_INCREMENT PRIMARY KEY,
    employee VARCHAR(40)
);

CREATE TABLE country (
    id INT AUTO_INCREMENT PRIMARY KEY,
    country VARCHAR(40)
);

CREATE TABLE client(
    id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
    name VARCHAR(40),
    email VARCHAR(40),
    sold BOOLEAN,
    date VARCHAR(40),
    email_type_id INT,
    employee_id INT,
    country_id INT,

    FOREIGN KEY(email_type_id) REFERENCES email_type(id),
    FOREIGN KEY(employee_id) REFERENCES employee(id),
    FOREIGN KEY(country_id) REFERENCES country(id)
);

Thank you so much!

Amelia W
  • 105
  • 1
  • 9

2 Answers2

1

how many clients are in each country

select country , count(*) from country  inner join client on country.id=client.country_id 
group by country 

how many clients each employee has

Select employee , count(*) from employee inner join client on client.employee_id =employee.id group by employee 
Ahmmed
  • 1,038
  • 1
  • 5
  • 13
0

Country's Count:

SELECT country , count(*) as countryCount from country INNER JOIN client on country.id=client.country_id GROUP BY country;

Employee's Count:

SELECT employee , count(*) as empCount from employee INNER JOIN client on client.employee_id =employee.id GROUP BY employee;

You can also hit this query:::

SELECT country , count(country) as countryCount from country INNER JOIN client on client.country_id=country.id GROUP BY country;

SELECT employee , count(employee) as empCount from employee INNER JOIN client on employee.i=client.employee_id GROUP BY employee;

In count(), I have passed column name.

David Buck
  • 3,752
  • 35
  • 31
  • 35
sweta
  • 1
  • 2