日期:2014-05-19  浏览次数:20398 次

这里有个SQL语句。大家看看效率如何?有没有更优形式?进者有分
如题
              String   sql   =   " ";
                sql   =   sql   +
                            "select   isnull(AcctName,CardUser.UserName)   as   name,t3.UserId   as   UserId,mapTab.area1   "   +
                            "area1,mapTab.area2   area2,Sed810.Sed810Name,t3.UserId   as   UserId,t3.CardType,t3.InTime,t3.OutTime   "   +
                            "from(   "   +
                            "select   "   +
                            "ISNULL(t1.UserId,   t2.UserId)   as   UserId,   "   +
                            "ISNULL(t1.Sed810Id,   t2.Sed810Id)   as   Sed810Id,   "   +
                            "ISNULL(t1.CardType,   t2.CardType)   as   CardType,   "   +
                            "t1.LogTime   as   InTime,   t2.LogTime   as   OutTime   "   +
                            "from   (   "   +
                            "select   *   "   +
                            ",(select   count(*)   from   CardLog   where   UserId=a.UserId   and   "   +
                            "Sed810Id=a.Sed810Id   and   CardType=a.CardType   and     "   +
                            "LogTime <=a.LogTime   and   LogTime> ' "   +   stime   +   " '   and     "   +
                            "LogTime <= ' "   +   etime   +   " ')   as   no   "   +
                            "from   CardLog   a   where   LockPart=1   and   LogTime> ' "   +   stime   +
                            " '   and   "   +
                            "LogTime <= ' "   +   etime   +   " ' "   +
    &nbs