【发布时间】:2017-09-12 19:10:09
【问题描述】:
我目前正在使用 pivot, unpivot 检索最后 6 个可用日期数据。谁能帮我解决这个问题?
select *
from #myTable
unpivot (value for Area in (abc,def,fgh,ijk,klp)) up
pivot (max(value) for [date] in (
##-- Here I need to get the last 6 available dates less than current date
)) p
[Date] 列的数据类型为DATE.
我的数据库中的日期样本值
2017-09-16,
2017-09-09,
2017-09-02,
2017-08-26,
2017-07-22,
2017-07-01,
2017-06-24,
2017-06-11
【问题讨论】:
-
每个区域的最后 6 个或最后 6 个?样本数据和预期输出会很好。
-
是的每个区域...添加了示例表,预期结果也相同..提前致谢...
标签: sql sql-server tsql pivot unpivot