hql语句查询去掉某一字段重复的行保留一行
1个回答
展开全部
参考如下:
/**
* 功能:根据品牌查询
*
* @param pageSize
* 每页大小
* @param currentLPagem
* 当前第几页
* @param productBlack
* 产品品牌
* @param productBlackItem
* 产品分类
* @param productSize
* 产品尺码
* @param keyWord
* 搜索关键字
* @return
*/
public pageBean seachProductByBrank(int pageSize, int currentLPage,
String product_Brank, String product_itemName) {
// final String hql = "from " + OgrilProducts.class.getName()
// + " where product_Brank='" + product_Brank
// + "' and product_itemName='" + product_itemName
// + "' order by product_registerDate desc";
final String hql = " from "
+ OgrilProducts.class.getName()
+ " as product where product.productItemName='"
+ product_itemName
+ "' and productBrank='"
+ product_Brank
+ "' and not exists( from "
+ OgrilProducts.class.getName()
+ " where productItemName='"
+ product_itemName
+ "' and productBrank='"
+ product_Brank
+ "' and productItemNumber=product.productItemNumber and productId<product.productId )";
int allRow = this.getAllRowCount(hql);// 总记录数
int totalPage = pageBean.countTotalpage(pageSize, allRow);// 总页数
final int offset = pageBean.countOffset(pageSize, currentLPage);// 当前页开始记录
final int length = pageSize;
final int currentPage = pageBean.countCurrentPage(currentLPage);
List list = this.queryForPage(hql, offset, length);// 记录
// 把分页信息保存到Bean中
pageBean pagebean = new pageBean();
pagebean.setPageSize(pageSize);
pagebean.setCurrentPage(currentPage);
pagebean.setAllRow(allRow);
pagebean.setTotalPage(totalPage);
pagebean.setList(list);
return pagebean;
}
/**
* 功能:根据品牌查询
*
* @param pageSize
* 每页大小
* @param currentLPagem
* 当前第几页
* @param productBlack
* 产品品牌
* @param productBlackItem
* 产品分类
* @param productSize
* 产品尺码
* @param keyWord
* 搜索关键字
* @return
*/
public pageBean seachProductByBrank(int pageSize, int currentLPage,
String product_Brank, String product_itemName) {
// final String hql = "from " + OgrilProducts.class.getName()
// + " where product_Brank='" + product_Brank
// + "' and product_itemName='" + product_itemName
// + "' order by product_registerDate desc";
final String hql = " from "
+ OgrilProducts.class.getName()
+ " as product where product.productItemName='"
+ product_itemName
+ "' and productBrank='"
+ product_Brank
+ "' and not exists( from "
+ OgrilProducts.class.getName()
+ " where productItemName='"
+ product_itemName
+ "' and productBrank='"
+ product_Brank
+ "' and productItemNumber=product.productItemNumber and productId<product.productId )";
int allRow = this.getAllRowCount(hql);// 总记录数
int totalPage = pageBean.countTotalpage(pageSize, allRow);// 总页数
final int offset = pageBean.countOffset(pageSize, currentLPage);// 当前页开始记录
final int length = pageSize;
final int currentPage = pageBean.countCurrentPage(currentLPage);
List list = this.queryForPage(hql, offset, length);// 记录
// 把分页信息保存到Bean中
pageBean pagebean = new pageBean();
pagebean.setPageSize(pageSize);
pagebean.setCurrentPage(currentPage);
pagebean.setAllRow(allRow);
pagebean.setTotalPage(totalPage);
pagebean.setList(list);
return pagebean;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询