代码之家  ›  专栏  ›  技术社区  ›  chamara

Count()有问题

  •  2
  • chamara  · 技术社区  · 15 年前

    我想写一个查询来检索 COUNT(of employees with the salary=1000) COUNT(of total no of employees) 从同一张桌子。 有什么想法吗??

    4 回复  |  直到 15 年前
        1
  •  2
  •   ToxicAvenger ToxicAvenger    15 年前
    select 
         count(*) totalCount, 
         count(case when salary = 1000 then 1 else NULL end) specialCount
    from Employees
    

    计数非空行。

        2
  •  5
  •   Tom H zenazn    15 年前

    另一种方法:

    SELECT
        COUNT(*) AS total_employees,
        SUM(CASE WHEN salary = 1000 THEN 1 ELSE 0 END) AS employees_with_1000_salary
    FROM
        Employees
    
        3
  •  3
  •   Nick    15 年前
        SELECT COUNT(EmployeeID) as 'Total Employees',   
        (SELECT COUNT(EmployeeID) FROM Employees WHERE Salary = 1000) as 'Salaried'
        FROM Employees 
    
        4
  •  0
  •   heisenberg    15 年前
    select count(*) as employeeCount,
    (select count(*) from employee where salary=1000) as bigmoneyEmployeeCount
    from employee
    
    推荐文章