3

我有 5 列:c1=Item、c2=LHrs、c3=WHrs、c4=Lead、c5=Worker,构造如下:

ITEM  LHRS  WHRS  LEAD  WORKER
123   25    10    John  Gary
456   15    20    John  John 

我希望结果看起来像这样:

RESOURCE  ITEM  HRS
John       123   25
Gary       123   10
John       456   35 

连接名称并执行结果“AS Resource”不会按照我想要的方式分解它。基本上我想知道每个人,每个项目,他们工作了多少小时,无论他们是领导(LHrs)还是工人(WHrs)。

想法?

4

1 回答 1

3

How about a UNION query?

SELECT item, person, sum(hrs) AS sumhours 
FROM (
   SELECT Item, lhrs as hrs,lead as person from wk
   UNION ALL
   SELECT Item, whrs, worker AS person from wk) a
GROUP BY item, person

Where wk is the name of the table.

于 2013-02-07T21:47:08.413 回答