如何提高下面语句的效率 select * from ( select a_month ,b_name ,count(DISTINCT a.c_no) , dense_rank() over (partition by a_month order by COUNT( DISTINCT a.c_no) desc) rank from sut_s a left join cou_c b on a.ll=b.ll where a_month>='10' group by b_name,a_month )where rank
select a_month ,b_name ,count(DISTINCT a.c_no) , dense_rank() over (partition by a_month order by COUNT( DISTINCT a.c_no) desc) rank from sut_s a left join cou_c b on a.ll=b.ll where a_month>='10' group by b_name,a_month having dense_rank() over (partition by a_month order by COUNT( DISTINCT a.c_no) desc)
但是where的话,还要把所有的字段都选择一遍,然后再where阿 having的话,在已有的基础上执行的话,个人觉得会快点。。赫赫 不过这里不能执行的话,估计也没有什么其他好方法了。 直接用top语句呢,不知道会不会效率高点 select top 10 a_month ,b_name ,count(DISTINCT a.c_no) from sut_s a left join cou_c b on a.ll=b.ll where a_month>='10' group by b_name,a_month order by count(DISTINCT a.c_no) desc