select avg(colname) from ( select top 2 colname from tb ) t
[code=SQL]select [col1], [col2], [col3], [col]=(select avg([col1]) from (select [col1] union all select [col2] union all select [col3])T) from tb [/code]
select [col1], [col2], [col3], [col]=(select avg([col1]) from (select [col1] union all select [col2] union all select [col3])T) from tb
select avg(col1),avg(col2),avg(col3) from ( select top 2 * from tb ) t
select *,id=identity(int,1,1) into #t from tbselect avg(colname) from (select top 2 colname from #t order by id desc )t
order by id desc这里用了倒叙 这里只需要对一个进行倒叙还算好,问题如果是我的数据库却还要两个倒叙 在这两列数据都是正序的情况下,几百W条数据居然用到了差不多分钟级别的时间, 而我取的只是几百条数据而已,所以....
呵呵,不是吧~你再看看我的需求好吗?? select top 400 日期+' '+时间 as 年月日时分秒-- from tableA order by 日期 desc,时间 desc数据量:773221[按日期和时间正序] SQL用的时间:3分41秒,只执行一次哦,呵呵,这让我怎么接受呀
select avg(colname) from
(
select top 2 colname from tb
) t
[col2],
[col3],
[col]=(select avg([col1])
from (select [col1]
union all select [col2]
union all select [col3])T)
from tb
[/code]
[col2],
[col3],
[col]=(select avg([col1])
from (select [col1]
union all select [col2]
union all select [col3])T)
from tb
(
select top 2 * from tb
) t
select *,id=identity(int,1,1) into #t from tbselect avg(colname) from
(select top 2 colname from #t order by id desc
)t
这里只需要对一个进行倒叙还算好,问题如果是我的数据库却还要两个倒叙
在这两列数据都是正序的情况下,几百W条数据居然用到了差不多分钟级别的时间,
而我取的只是几百条数据而已,所以....
select top 400 日期+' '+时间 as 年月日时分秒--
from tableA
order by 日期 desc,时间 desc数据量:773221[按日期和时间正序]
SQL用的时间:3分41秒,只执行一次哦,呵呵,这让我怎么接受呀