作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有表 A,如何从表 A 中选择以获得表 B 格式?
Table A
Employee Name Effective Date FieldType FieldValue
Maung Mya 1/1/2005 Title Project Engineer
Maung Mya 1/1/2005 Department IT Department
Maung Mya 1/1/2007 Title Assist Project Manager
Kyaw Kyaw 1/1/2006 Title Software Engineer
Kyaw Kyaw 1/1/2006 Department IT Department
Table B
Effective Date Employee Name Title Department
1/1/2007 Maung Mya Assist Project Manager IT Department
1/1/2006 Kyaw Kyaw Software Engineer IT Department
最佳答案
看起来你想要这样的东西:
SELECT A.[Effective Date],
A.[Employee Name],
A.FieldValue AS Title,
A2.FieldValue AS Department
FROM A INNER JOIN
A AS A2
ON A.[Employee Name] = A2.[Employee Name] AND
A.[Effective Date] = A2.[Effective Date] AND
A.FieldType = 'Title' AND
A2.FieldType = 'Department'
WHERE A.[Effective Date] = (
SELECT MAX([Effective Date])
FROM A AS A3
WHERE A3.[Employee Name] = A.[Employee Name] AND A3.FieldType = 'Title')
AND A2.[Effective Date] = (
SELECT MAX([Effective Date])
FROM A AS A4
WHERE A4.[Employee Name] = A2.[Employee Name] AND A3.FieldType = 'Department')
关于sql-server-2005 - SQL 服务器 : How can I SELECT FROM TABLE TO Other Format?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2501515/
我是一名优秀的程序员,十分优秀!