gpt4 book ai didi

sql-server-2005 - SQL 服务器 : How can I SELECT FROM TABLE TO Other Format?

转载 作者:行者123 更新时间:2023-12-01 13:06:52 24 4
gpt4 key购买 nike

我有表 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com