两表左连接,统计第二张表中的个数(many-to-one)

在hbm.xml文件里加上

              <set name="ewrtcpu" >
              <!--key元素用于指定关联的字段 -->
                <key column="BELONG_ID"/>
                <!-- 一个用户对应多篇文章 -->
                <one-to-many class="com.canon.ediweb.model.EwRtCpu" />  
        </set>

在相关的POJO文件中加上

               private Set ewrtcpu= new HashSet();

sql语句中

             String sqlstr = "select new map (vm.vendorId as vendorId,"
  + " vm.vendorName as vendorName,"
  + " vm.userAlpha3 as vendorType,"
  + " vm.vendorAddress as vendorAddress,"
  + " vm.guanwuName as guanwuName,"
  + " vm.guanwuTel as guanwuTel,"
  + " vm.guanwuEmail as guanwuEmail,"
  + " vm.guanwubosName as guanwubosName,"
  + " vm.guanwubosTel as guanwubosTel,"
  + " vm.guanwubosEmail as guanwubosEmail,"
  + " vm.yinyeName as yinyeName," + " vm.yinyeTel as yinyeTel,"
  + " vm.yinyeEmail as yinyeEmail,"
  + " count(cpu.cpuId) as cpuNumber,"
  + " vm.vendorRemark as vendorRemark) "
  + " from VendorMast vm left join vm.ewrtcpu cpu "
//  + " where vm.ewrtcpu.belongId = vm.vendorId "
  + " group by vm.vendorId," + " vm.vendorName,"
  + " vm.userAlpha3," + " vm.vendorAddress," + " vm.guanwuName,"
  + " vm.guanwuTel," + " vm.guanwuEmail," + " vm.guanwubosName,"
  + " vm.guanwubosTel," + " vm.guanwubosEmail,"
  + " vm.yinyeName," + " vm.yinyeTel," + " vm.yinyeEmail,"
  + " vm.vendorRemark";

其中 “where vm.ewrtcpu.belongId = vm.vendorId ”省略不写。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值