今天在CSDN上看见一个分页存储过程,里面有一句SQL不懂.
SET @SQLSTR='select top '+convert(varchar,@PageSize)
+' RecordID,myDateTime,MoneyType,MoneyNum,myKeyword,Others FROM [MoneyRecord] t'
+' where (select count(1) from [MoneyRecord] where RecordID>t.RecordID and UserID=t.UserID)+1>'
+convert(varchar,@PageSize*(@PageIndex-1))
+' and UserID='''+convert(varchar,@strUserID)+''''
+' order by RecordID desc'
其中这句话是什么意思呢
select count(1) from [MoneyRecord] where RecordID>t.RecordID and UserID=t.UserID
我用
select count(1) from news where ID>news.ID and ID=news.ID+1得到的是0.
该贴原址在
http://community.csdn.net/Expert/topic/4404/4404643.xml?temp=.7459986
SET @SQLSTR='select top '+convert(varchar,@PageSize)
+' RecordID,myDateTime,MoneyType,MoneyNum,myKeyword,Others FROM [MoneyRecord] t'
+' where (select count(1) from [MoneyRecord] where RecordID>t.RecordID and UserID=t.UserID)+1>'
+convert(varchar,@PageSize*(@PageIndex-1))
+' and UserID='''+convert(varchar,@strUserID)+''''
+' order by RecordID desc'
其中这句话是什么意思呢
select count(1) from [MoneyRecord] where RecordID>t.RecordID and UserID=t.UserID
我用
select count(1) from news where ID>news.ID and ID=news.ID+1得到的是0.
该贴原址在
http://community.csdn.net/Expert/topic/4404/4404643.xml?temp=.7459986
和
select count(1) from [MoneyRecord] where RecordID>t.RecordID and UserID=t.UserID
的意义完全不一样,后者的RECORDID是T表中的字段,而你自己写的SQL的ID和NEWS.ID都是同一张表的字段,所以选出来满足条件的行数为0
select count(1) from [MoneyRecord] 是MoneyRecord表,t表也是MoneyRecord表?
是条件子表中的语句,t为外面表[MoneyRecord]的别名
分开来用含义当然不同了,不可分开独立使用