SQL 杂活

例子一:查询两个表数据并且分页展示

select * from (
select ROW_NUMBER() OVER(order by CreateTime desc) as rownum,* from (
(select SP_Approval.ApprovalTypeID,  SP_Approval.CreateTime, SP_Approval.ID,U_User.LinkMan   
FROM SP_Approval LEFT OUTER JOIN U_User ON SP_Approval.UserID = U_User.ID  
where   UserID=1903 and ApprovalState=0 )  
 union all 
(select Sp_Borrowing.ApprovalTypeID, Sp_Borrowing.CreateTime, Sp_Borrowing.ID,U_User.LinkMan 
 FROM Sp_Borrowing LEFT OUTER JOIN U_User ON Sp_Borrowing.UserID = U_User.ID
 where  UserID=1903 and ApprovalState=0  )
 ) as t 
 ) as p
 where rownum between 1 and 20 order by CreateTime desc
查询两个表数据并且分页展示

 

 例子二:Linq语句

//linq 分页代码
output.ReList.OrderByDescending(t => t.CreateTime).Skip(20 * (PageSize - 1)).Take(20).ToList();
UserList.FindAll(t=>t.Role==reM.RoleName);
//把所有的对象查出来放入实体类里 然后按支付方式进行排序 然后再按时间排序 然后再进行分页 
//OrderBy 是排序(后面是条件)然后要查询所有的,在所有的数据中在查询你要分页的数据,skip是在分页在前有多少条数据,也就是在当前页数据之前的数据总和,(跳过序列中指定数量的元素,然后返回剩余的元素。)pageSize*(pageIndex-1),Take 是返回多少条数据,也就是pageSize!
output.ReList = output.ReList.OrderByDescending(t => t.PayTpye).ThenByDescending(t => t.CreateTime).Skip(20 * (page -
1)).Take(20).ToList();
reM.ToNum = catLL.Find(
                                    delegate(Model.Product.YuanpianCatModel ddM)
                                    {
                                        return ddM.ProductID == int.Parse(reM.ID);
                                    }
                                    ).ToNum.ToString();
                      string  oNum = catLL.Find(z => z.ProductID == int.Parse(reM.ID)).ToNum.ToString();
Find

 

posted @ 2017-12-04 16:56  革凡  阅读(134)  评论(0编辑  收藏  举报