如何使用连接从两个表中创建一个视图,从另一个表中显示COUNT?

时间:2017-05-27 05:27:21

标签: mysql sql database

    CREATE VIEW EMPJOBS AS 
     SELECT EMPLOYEE.employee_id AS ENUM, 
     CONCAT(EMPLOYEE.first_name, 
     ' ' , EMPLOYEE.last_name) AS NAME, 
     EMPLOYEE.email AS EMAIL, 
     COUNT(JOBHISTORY.end_date) AS FINISHEDJOBS
    FROM EMPLOYEE, JOBHISTORY
    WHERE JOBHISTORY.employee_id = EMPLOYEE.employee_id;

这就是我的陈述。我知道这是错的,因为它显示了这个:

enter image description here

它将end_date统计为一个大数。我怎么能计算每一个单独的ENUM?

谢谢!

2 个答案:

答案 0 :(得分:1)

在最后添加 // Location of webpack output output: { path: path.join(__dirname, 'dll'), filename: '[name].bundle.js', library: '[name]' }, plugins: [ new webpack.DllPlugin({ path: require(path.join(__dirname, 'dll/[name]-manifest.json')), name: '[name]', }) ] 子句。

group by

作为最佳做法,请尝试使用正确的连接语法来连接表而不是使用逗号。还为表名添加别名以避免混淆和可读性。

答案 1 :(得分:0)

您也可以这样做:

CREATE VIEW EMPJOBS AS 
  SELECT EMPLOYEE.employee_id AS ENUM, 
  CONCAT(EMPLOYEE.first_name, ' ' , EMPLOYEE.last_name) AS NAME, 
  EMPLOYEE.email AS EMAIL,
  Select(COUNT(end_date) From JOBHISTORY jh where jh.employee_id = E.employee_id) AS FINISHEDJOBS
 FROM EMPLOYEE E;