如何提高GROUP BY分组查询效率 最近工作中遇到一个性能问题,自己搞了好久还是没搞定,拿到论坛上来,希望各位大虾给点意见。 查询的SQL如下: SELECT A,B,C,D,COUNT(1) FROM T WHERE C=@C AND D IN (@D) GROUP BY A,B 因为数据量比较大,所以这条SQL效率就变得特别慢,而且这个是用在页面查询上的,分页后每次查询都要花到8到9秒钟,页面卡死在那边,希望高手们帮小弟解答,小弟这边先谢过了。 性能 sql group?by [解决办法]
OFFER_NAME, CHANNEL_ID, SUB_CHANNEL_ID, DISTY_ID, DISTY_BUSCODE, DISTY_NAME, REGION_CODE, REGION_NAME, O_ACTIVATION_TIME, P_ACTIVATION_TIME, ACTIVATION_DATE, STATE_CODE, STATE_NAME, PACKAGE_ID, PACKAGE_NAME, SALES_PIC, MSISDN, COUNT(1) FROM UM2_ACTI_DTL_201305 WHERE OFFER_TYPE IN(1,3) AND ACTIVATION_TYPE = 3 AND OFFER_ID IN(20000001,20000031,20010010) AND PACKAGE_ID IN(322,197,326,566,318,576,277,374,377,581) AND CHANNEL_ID IN(1,2,4) GROUP BY DEALER_ID,PACKAGE_ID,ACTIVATION_DATE