mssql命令行按asc排序所有行但最后两行

时间:2016-12-05 08:23:34

标签: sql-server sql-server-2012 sql-order-by

在工会之后需要帮助订购

select sno,measurement from measurementTable union all select '' as sno,avg(measurement) as 
measurement from measurementTable union all select '' as sno,
max(measurement)-min(measurement) from measurementTable;

我需要在datagrid的底部显示平均值,但是命令所有其他mssql服务器表行按sno升序 我试图在联合之前使用order by并且出错

select sno,measurement from measurementTable order by sno asc union all select '' as sno,
avg(measurement) as measurement from measurementTable union all select '' as sno,
max(measurement)-min(measurement) from measurementTable;

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'union'.

是否可以在联合之前使用order by?

0 个答案:

没有答案