【问题标题】:Querying multiple tables using aggregate functions使用聚合函数查询多个表
【发布时间】:2013-10-07 21:37:04
【问题描述】:

我正在尝试查询 3 个表以提供 user nameSUMhoursjob title

SELECT e.sname, t.hours, p.job
FROM emoployee e, time t c, position p
WHERE e.e_id = t.sid AND t.position_id = p.position_id

我可以获得namehours 每班和position,但每次班都会重复。

如何使用SUM 函数给我employee name(仅显示一次)及其总数hoursposition

【问题讨论】:

    标签: sql sum distinct aggregate


    【解决方案1】:

    这是通过group by 子句完成的:

    SELECT e.sname, p.job, sum(t.hours)  
    FROM employee e, time t, position p 
    WHERE e.e_id = t.sid 
      AND t.position_id = p.position_id
    GROUP BY e.sname, p.job 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多