【发布时间】:2016-03-11 02:18:47
【问题描述】:
with a as (
select a.*, row_number() over (partition by department order by attributeID) rn
from attributes a),
e as (
select employeeId, department, attribute1, 1 rn from employees union all
select employeeId, department, attribute2, 2 rn from employees union all
select employeeId, department, attribute3, 3 rn from employees
)
select e.employeeId, a.attributeid, e.department, a.attribute, a.meaning,
e.attribute1 as value
from e join a on a.department=e.department and a.rn=e.rn
order by e.employeeId, a.attributeid
此查询由 Ponder Stibbons 编写,用于回答 this 问题。但是我对此感到头晕目眩,因为我完全不明白这里发生了什么。我是 SQL 新手。所以如果有人能解释这个查询发生了什么,我将不胜感激。谢谢你
【问题讨论】: