我从T-SQL中的视图创建了以下临时表:
Id | Expiration Date | Expiration Update Date
--------------------------------------------------------
38 | 2018-01-31 00:00:00.000 | Dec 13 2017 6:28PM
37 | 2017-08-31 00:00:00.000 | Jun 1 2017 6:15PM
37 | 2017-06-15 00:00:00.000 | May 10 2017 8:33PM
38 | 2017-12-31 00:00:00.000 | Nov 21 2017 3:38PM
37 | 2018-03-31 00:00:00.000 | Feb 16 2018 7:10PM
38 | 2018-09-30 00:00:00.000 | Mar 13 2018 2:29PM
37 | 2018-01-31 00:00:00.000 | Dec 13 2017 6:28PM
39 | 2018-10-31 00:00:00.000 | Jan 22 2018 6:38PM
37 | 2017-06-30 00:00:00.000 | May 9 2017 8:30PM
37 | 2017-12-31 00:00:00.000 | Nov 21 2017 3:38PM
39 | 2018-08-31 00:00:00.000 | Jan 2 2018 4:08PM
我想创建将其显示为
的查询 Id | Expiration Date 1| Update Date 1 | Expiration Date 2| Update 2
-----------------------------------------------------------------------------
37 | 2017-06-30 | Nov 21 2017 3:38PM | 2017-12-31 |Nov 21 2017 3:38PM
38 | 2017-12-31 | Nov 21 2017 3:38PM | 2018-01-31 |Dec 13 2017 6:28PM
39 | 2018-08-31 | Jan 2 2018 4:08PM | 2018-10-31 |Jan 22 2018 6:38PM
我删除了到期日的时间戳以节省空间。这个想法是为该ID的到期日期的每个实例创建一个新列,同时在系统中更新该到期日期的第二列。捕获是每个想法没有相同数量的到期日期,因此具有较少过期日期的ID将具有额外列的NULL值,我可以使用。