如何将列中的日期值转换为多列的日期
我需要在SSM中使用T-SQL启动此表。我不需要汇总任何东西,也无法预测每张票的更新日期。我在上使用row_number()强制第一个表中的排序,我需要在所需的表中维护票务的水平日期。
有人对如何执行此操作有任何想法吗?
更改此表:
Rownum | 票 | 更新 |
---|---|---|
1 | 1 | 1/1/2022 |
2 | 1 | 1/3/2022 |
1 | 2 | 1/27/2022 |
1 | 3 | 3/1/2022 |
2 | 3 | 4/2/2022 |
3 | 3 3 | 3/1/2022 1/2022 |
1 | 4 | 7/11/2022 |
到这张表:
票务 | DT1 | DT2 | DT3 |
---|---|---|---|
1 | 1/1/2022 | 1/3/2022 | |
2 | 1/27/2022 | ||
3 3 | 3/1/2022 | 4/2/2022 | 5/3/2022 |
4 | 7/11/2022 |
I need to unpivot this table using T-SQL in SSMS. I don't need to aggregate anything and I am not able to predict the update dates for each ticket. I am using row_number() over partition by
to force the sort in the first table and I need to maintain the horizontal sort of dates by ticket in the desired table.
Does anyone have any ideas on how to do this?
Change this table:
rownum | ticket | updated |
---|---|---|
1 | 1 | 1/1/2022 |
2 | 1 | 1/3/2022 |
1 | 2 | 1/27/2022 |
1 | 3 | 3/1/2022 |
2 | 3 | 4/2/2022 |
3 | 3 | 3/1/2022 |
1 | 4 | 7/11/2022 |
to this table:
ticket | Dt1 | Dt2 | Dt3 |
---|---|---|---|
1 | 1/1/2022 | 1/3/2022 | |
2 | 1/27/2022 | ||
3 | 3/1/2022 | 4/2/2022 | 5/3/2022 |
4 | 7/11/2022 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
dbfiddle