标签:数据库分页语句
<%
DBHelper db = DBHelper.getInstance();
Long sid=Common.getLong(SessionTools.currentWebsite(request).get("id"));
Map obj = new HashMap();
//获取当前页
String catId = Common.getString(request,"catId",true);
Map newObj = new HashMap();
if(catId==null||"".equals(catId)){
newObj = db.map("SELECT TOP 1 cat.id id,data.field3 field3 FROM wcm_cms_news_cat cat INNER JOIN wcm_common_universal_data data on cat.id=data.data_id WHERE cat.sid =? AND cat.is_show = 1 ORDER BY cat.orderno ASC, cat.id DESC",new Object[]{sid});
}else{
newObj = db.map("SELECT cat.id id, data.field3 field3 FROM wcm_cms_news_cat cat INNER JOIN wcm_common_universal_data data ON cat.id = data.data_id WHERE cat.id=? AND cat.is_show = 1",new Object[]{catId});
}
if(newObj!=null){
String field3=Common.getString(newObj.get("field3")); //举办时间
obj.put("y1",field3.substring(0,1));
obj.put("y2",field3.substring(1,2));
obj.put("y3",field3.substring(2,3));
obj.put("y4",field3.substring(3,4));
obj.put("y5",field3.substring(5));
String newId = Common.getString(newObj.get("id"));
catId = newId;
obj.put("newObj",newObj);
}
//取上一年
Map preObj = db.map("WITH temp AS(SELECT row_number()OVER(ORDER BY orderno asc,id DESC)row_number,* FROM wcm_cms_news_cat WHERE is_show = 1 AND sid =?)SELECT * FROM temp WHERE row_number =( SELECT row_number - 1 FROM temp WHERE id =?)",new Object[]{sid,catId});
if(preObj!=null){
obj.put("preObj",preObj);
}
//下一年
Map nextObj = db.map("WITH temp AS(SELECT row_number()OVER(ORDER BY orderno asc,id DESC)row_number,* FROM wcm_cms_news_cat WHERE is_show = 1 AND sid =?)SELECT * FROM temp WHERE row_number =( SELECT row_number + 1 FROM temp WHERE id =?)",new Object[]{sid,catId});
if(nextObj!=null){
obj.put("nextObj",nextObj);
}
jspContext.setAttribute("obj",obj);
%>
标签:数据库分页语句
原文地址:http://8648389.blog.51cto.com/8638389/1641524