日期:2014-05-18  浏览次数:20470 次

百万条数据,如何提高查询、比较以及更新处理的速度
C# code

public int[] counts()
{
        int[] zj;
        int y1= 0;
        int y2= 0;
        int y3= 0;
        int y4= 0; 
    IList<tb_ssq> listSsq = (from ls in cpjc.tb_ssq where ls.tb_ssq_QiShu == 2011129 orderby ls.tb_ssq_JieZhiTime descending select ls).ToList();
if (listSsq.Count != 0)
        {
            ArrayList al = new ArrayList { 1, 2, 3, 4, 5, 6};
            ArrayList alBlue = new ArrayList { 7};
            for (int i = 0; i < listSsq.Count; i++)
            {
                int countH = 0;    //统计红球中奖个数
                int countL = 0;    //统计篮球是否中奖
                if (al.Contains(listSsq[i].tb_ssq_h1))
                    countH++;
                if (al.Contains(listSsq[i].tb_ssq_h2))
                    countH++;
                if (al.Contains(listSsq[i].tb_ssq_h3))
                    countH++;
                if (al.Contains(listSsq[i].tb_ssq_h4))
                    countH++;
                if (al.Contains(listSsq[i].tb_ssq_h5))
                    countH++;
                if (al.Contains(listSsq[i].tb_ssq_h6))
                    countH++;
                if (alBlue.Contains(listSsq[i].tb_ssq_l1))
                    countL++;
                if (countH == 6 && countL == 1)
                {
                    y1++;
                    listSsq[i].tb_ssq_state= 2; 
                }
                else if (countH == 6 && countL == 0)
                {
                    y2++;
                    listSsq[i].tb_ssq_state = 2;
                }
                else if (countH == 5 && countL == 1)
                {
                    y3++;
                    listSsq[i].tb_ssq_state = 2;
                }
                else if ((countH == 5 && countL == 0) || (countH == 4 && countL == 1))
                {
                    y4++;
                    listSsq[i].tb_ssq_state = 2;
                }
                else if ((countH == 4 && countL == 0) || (countH == 3 && countL == 1))
                {
                    listSsq[i].tb_ssq_state = 2;
                }
                else if (countL == 1)
                {
                    listSsq[i].tb_ssq_state = 2;
                }
                else
                {
                    listSsq[i].tb_ssq_state = 1;
                } 
            }
            cpjc.SubmitChanges();
        }
        zj = new int[] { y1, y2,y3, y4};
        return zj;

}



如上所示代码,tb_ssq表中有100条数据,如何提高该自定义方法counts()的执行处理速度,即查询数据、比较数据、更新数据的速度???

------解决方案--------------------
这个需要很多方面去优化,服务器,数据库,sql语句,客户端(分页,按提条件查询)等等,慢慢来吧
------解决方案--------------------
看起来像是7星彩的中将统计,
你描述下你的实际业务需求,
我看看能不能给你一个比较快的解决办法。
------解决方案--------------------
请看我在你另一个帖子里的回复