答案 0 :(得分:2)
要获得给定的输出,您可以按照以下步骤操作;
Select
DISTINCT(
'Change From '+ Cast(initial AS Varchar(10))+' to '+Cast(final AS Varchar(10))
) AS DATA
,SUM(Case When year=2017 Then 1 Else 0 END) AS [2017]
,SUM(Case When year=2016 Then 1 Else 0 END) AS [2016]
From Input_table
Group By initial, final
ORDER BY DATA ASC
注意: - 如果您真实地使用它。然后可能是我可以建议,然后更好的解决方案。
答案 1 :(得分:0)
ORDER BY子句。还有SQL Server specific
SELECT * FROM Input_table ORDER BY initial