按 DESC 订购的替代方案
Alternative for order by DESC
此 sql 查询获取记录总共需要 9 分钟..
select top 1 checkdate
from BTHI1
where CUSTOMERID = 'AUTOMO' and recordtype='T'
order by checkdate desc
还有其他方法可以减少查询时间吗?
对于这个查询:
select top 1 checkdate
from BTHI1
where CUSTOMERID = 'AUTOMO' and recordtype = 'T'
order by checkdate desc
您想要 BTH1(CUSTOMERID, recordtype, checkdate DESC)
上的索引。前两列可以按任意顺序排列。
注意你也可以这样写:
select max(checkdate)
from BTHI1
where CUSTOMERID = 'AUTOMO' and recordtype = 'T';
此 sql 查询获取记录总共需要 9 分钟..
select top 1 checkdate
from BTHI1
where CUSTOMERID = 'AUTOMO' and recordtype='T'
order by checkdate desc
还有其他方法可以减少查询时间吗?
对于这个查询:
select top 1 checkdate
from BTHI1
where CUSTOMERID = 'AUTOMO' and recordtype = 'T'
order by checkdate desc
您想要 BTH1(CUSTOMERID, recordtype, checkdate DESC)
上的索引。前两列可以按任意顺序排列。
注意你也可以这样写:
select max(checkdate)
from BTHI1
where CUSTOMERID = 'AUTOMO' and recordtype = 'T';