我的员工表中的示例我有这些数据
//EMPLOYEE
E# NAME CITY
--------------------------
1 JOHN ENGLAND
2 SITI ENGLAND
3 JESS GERMANY
4 HOLY BOSTON
当我运行此声明时:
SELECT DISTINCT CITY, COUNT(E#) as "Total Employee" FROM EMPLOYEE Where CITY=;
我应该为
插入什么值//CITY=?
为了得到像这样的结果
CITY TOTAL EMPLOYEE
----------------------------
ENGLAND 2
GERMANY 1
BOSTON 1
是不是可以使用group by或having子句?
答案固定!致谢
答案 0 :(得分:4)
嗯,你不是排除任何城市,所以你根本不需要WHERE
条款!但是你需要GROUP BY
来计算。你可以这样做:
SELECT CITY, COUNT(E#) as "Total Employee"
FROM EMPLOYEE
GROUP BY CITY
但是,如果仅想要包含这三个城市(即使将更多内容添加到基础数据中),您可以执行以下操作:
SELECT CITY, COUNT(E#) as "Total Employee"
FROM EMPLOYEE
WHERE CITY IN ('ENGLAND', 'GERMANY', 'BOSTON')
GROUP BY CITY