我是 SQL 的超级新手,一直在处理这个查询,但似乎无法让它工作。我需要总结类别(每个国家有多少客户以及每个员工有多少客户)。这是我试图在每个国家/地区获得总客户的方法:
COUNT(*) TotalCount,
country.id, country.country
FROM client
INNER JOIN country
ON client.country_id = country.id
GROUP BY country.id, country.country
这些是我的表:
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)
);
太感谢了!