贴sql语句。
alter proc proc_IntegralMng(@page int,@pagesize int)
as
select Integral.ID,PhoneUserInfo.RealUserName,Integral.Integral,IntegralStatus.LoginNumber,
IntegralStatus.CommentNumber,IntegralStatus.ShareNumber,IntegralStatus.PublishNumber,IntegralStatus.StatusTime
from Integral
left join IntegralStatus on Integral.UserID = IntegralStatus.LoginID
left join PhoneUserInfo on PhoneUserInfo.Id = Integral.UserID
where IntegralStatus.LoginID <> 0 and PhoneUserInfo.RealUserName is not null and
PhoneUserInfo.RealUserName <> '' order by Integral.integral desc,StatusTime desc
where PhoneUserInfo.RealUserName+IntegralStatus.StatusTime not in
(select top(@pagesize * (@page-1)) PhoneUserInfo.RealUserName+IntegralStatus.StatusTime from Integral
left join IntegralStatus on Integral.UserID = IntegralStatus.LoginID
left join PhoneUserInfo on PhoneUserInfo.Id = Integral.UserID
where IntegralStatus.LoginID <> 0 and PhoneUserInfo.RealUserName is not null and
PhoneUserInfo.RealUserName <> '' order by Integral.integral desc,StatusTime desc)
and IntegralStatus.LoginID <> 0 and PhoneUserInfo.RealUserName is not null and
PhoneUserInfo.RealUserName <> '' order by Integral.integral desc,StatusTime desc
另外,这个sql分页可以优化一下么 ?我觉得如果去除重复的了就不用PhoneUserInfo.RealUserName+IntegralStatus.StatusTime来作为唯一建了,那样应该更好吧!
sql asp.net
------解决方案--------------------
建了唯一索引也一样,问题是你要把后面那些数据如何展示,如果转成列,就可以成为一行,否则很难去重,重点还是想看你怎么展示
------解决方案--------------------
但是从数据上来看,它的确是唯一的,只是你不想展示这么多而已,要么只取比如日期最大的那条,要么转成列,要么把所谓“重复”的列,组成一列,比如4,12,6,0这个作为一列展示