我有 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”并没有按照我想要的方式分解它。基本上我想知道每个人,每个项目,他们工作了多少小时,无论他们是 Lead (LHrs) 还是 Worker (WHrs)。
想法?
最佳答案
UNION 查询怎么样?
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
其中 wk 是表的名称。
关于sql - 在 MS Access 中将 2 个相似字段合并为 1 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14761511/