In SQL Server, I would recommend apply
:
select v.*
from t cross apply
(values (id1, date1, status1), (id2, date2, status2)
) v(id, date, status);
Note that column names cannot be duplicated in a table. So, this assumes that the columns actually have different names.
This approach is preferred over union all
because it only scans the table once. For a small table, the performance difference is negligible. It is noticeable for larger tables and can be quite significant if the "table" is really a subquery, CTE, or view.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…