hql 多表连接查询
来源:互联网 发布:淘宝卖家的快递费 编辑:程序博客网 时间:2024/05/02 00:34
到网了找了N久的资料,没看到一个满意的答案``还是自己发点时间研究了一下。
原码如下:
/**
* 统计
*
* @return
* @throws BusinessExceptions
*/
public List statistic(Integer type, String productId, String clientId,
Date dateBirthday1, Date dateBirthday2, String storeId,
Integer price, String employeeId) throws BusinessExceptions {
StringBuffer sb = new StringBuffer("select new map(");
sb.append("osbi.id as id ,");
sb.append("osbi.sku.product.name as productName,");
sb.append("osbi.sku.color.name as colorName,");
sb.append("osbi.sku.size.name as sizeName,");
sb.append("osbi.outStoreBill.employee.name as employeeName,");
sb.append("osbi.outStoreBill.client.name as clientName,");
sb.append("osbi.outStoreBill.store.name as storeName,");
sb.append("sum(osbi.price) as totalPrice,");
sb.append("sum(osbi.quantity) as totalQuantity ");
sb.append(") from OutStoreBillItem as osbi ");
sb.append("left join osbi.sku left join osbi.outStoreBill ");
sb.append("left join osbi.sku.product ");
sb.append("left join osbi.sku.color ");
sb.append("left join osbi.sku.size ");
sb.append("left join osbi.outStoreBill.store ");
sb.append("left join osbi.outStoreBill.client ");
sb.append("left join osbi.outStoreBill.employee ");
sb.append(" where osbi.outStoreBill.type = ?");
sb.append(" and osbi.sku.product.id = ?");
// sb.append(" and osbi.outStoreBill.state = ?");
// sb.append(" and osbi.outStoreBill.client.id = ?");
sb.append(" and osbi.outStoreBill.createTime between ? and ?");
sb.append(" and osbi.outStoreBill.store.id = ?");
// sb.append(" and osbi.outStoreBill.employee.id = ?");
sb.append(" group by osbi.sku.id");
return this.find(sb.toString(), type, productId, dateBirthday1,
dateBirthday2, storeId);
}
OutStoreBillItem 对像中有一个outStoreBill的属性,OutStoreBill对像中又有store,client,employee等属性。
OutStoreBillItem 对像中有一个sku的属性,Sku对像中又有product等属性
上例统计OutStoreBillItem表。left join了 outStoreBill表。而outStoreBill又left join了store,client,employee三表。
原码如下:
/**
* 统计
*
* @return
* @throws BusinessExceptions
*/
public List statistic(Integer type, String productId, String clientId,
Date dateBirthday1, Date dateBirthday2, String storeId,
Integer price, String employeeId) throws BusinessExceptions {
StringBuffer sb = new StringBuffer("select new map(");
sb.append("osbi.id as id ,");
sb.append("osbi.sku.product.name as productName,");
sb.append("osbi.sku.color.name as colorName,");
sb.append("osbi.sku.size.name as sizeName,");
sb.append("osbi.outStoreBill.employee.name as employeeName,");
sb.append("osbi.outStoreBill.client.name as clientName,");
sb.append("osbi.outStoreBill.store.name as storeName,");
sb.append("sum(osbi.price) as totalPrice,");
sb.append("sum(osbi.quantity) as totalQuantity ");
sb.append(") from OutStoreBillItem as osbi ");
sb.append("left join osbi.sku left join osbi.outStoreBill ");
sb.append("left join osbi.sku.product ");
sb.append("left join osbi.sku.color ");
sb.append("left join osbi.sku.size ");
sb.append("left join osbi.outStoreBill.store ");
sb.append("left join osbi.outStoreBill.client ");
sb.append("left join osbi.outStoreBill.employee ");
sb.append(" where osbi.outStoreBill.type = ?");
sb.append(" and osbi.sku.product.id = ?");
// sb.append(" and osbi.outStoreBill.state = ?");
// sb.append(" and osbi.outStoreBill.client.id = ?");
sb.append(" and osbi.outStoreBill.createTime between ? and ?");
sb.append(" and osbi.outStoreBill.store.id = ?");
// sb.append(" and osbi.outStoreBill.employee.id = ?");
sb.append(" group by osbi.sku.id");
return this.find(sb.toString(), type, productId, dateBirthday1,
dateBirthday2, storeId);
}
OutStoreBillItem 对像中有一个outStoreBill的属性,OutStoreBill对像中又有store,client,employee等属性。
OutStoreBillItem 对像中有一个sku的属性,Sku对像中又有product等属性
上例统计OutStoreBillItem表。left join了 outStoreBill表。而outStoreBill又left join了store,client,employee三表。
- hql 多表连接查询
- HQL实现多表连接+多条件查询
- hql 多表查询
- hql多表查询
- HQL多表查询
- HQL多表查询
- HQL多表查询
- HQL多表查询
- HQL多表查询
- HQL (九) 连接查询
- HQL 连接查询
- HQL连接查询
- HQL连接查询【重要】
- Hql连接查询
- HQL的多表查询
- HQL的多表查询
- hibernate多表查询HQL
- hibernate多表查询HQL
- 被遗弃的城市
- C++ inline 解释
- 用**248##命令进工程模式快速检测HCK G801验机方法
- 女孩
- 关于build.xml和外部配置文件的使用
- hql 多表连接查询
- 满江红
- js:限制页面必须在框架内·完美版:保证父框架启动的后,自动打开原来页面!
- HKC G801铃声音量增大办法
- 一个实际开发项目的build.xml参考
- 雨霖铃
- delphi事件处理
- Catalyst 2950/2960 密码恢复方法
- Windows Server 2008 之 Server Core、IIS7.0