码迷,mamicode.com
首页 > 其他好文 > 详细

三表左外连接的实例

时间:2015-03-09 17:33:35      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:sql oracle

String hql="select js_product_warehouse.c_id,js_product_warehouse.c_product_id,js_product_warehouse.c_stock,nvl(m.sumEnterWarehouse,0),nvl(n.sumOutWarehouse,0),nvl(m.enterWarehouseDate,n.outWarehouseDate) stockReportDate from "+
           "js_product_warehouse "+
    "left join (select js_product_warehouse_detail.c_product_warehouse_id product_warehouse_id,sum(js_product_warehouse_detail.c_enter_warehouse) sumEnterWarehouse,js_product_warehouse_detail.c_enter_warehouse_date enterWarehouseDate from js_product_warehouse_detail where js_product_warehouse_detail.c_is_del=‘1‘ group by js_product_warehouse_detail.c_product_warehouse_id,js_product_warehouse_detail.c_enter_warehouse_date) m on js_product_warehouse.c_id=m.product_warehouse_id "+
    "left join (select js_product_sale_detail.c_product_warehouse_id product_warehouse_id,sum(js_product_sale_detail.c_out_warehouse) sumOutWarehouse,js_product_sale_detail.c_out_date outWarehouseDate from js_product_sale_detail where js_product_sale_detail.c_is_del=‘1‘ group by js_product_sale_detail.c_product_warehouse_id,js_product_sale_detail.c_out_date) n on js_product_warehouse.c_id=n.product_warehouse_id and m.enterWarehouseDate=n.outWarehouseDate  where js_product_warehouse.c_is_del=‘1‘ "+
   "order by js_product_warehouse.c_product_id,nvl(m.enterWarehouseDate,n.outWarehouseDate)";

三表左外连接的实例

标签:sql oracle

原文地址:http://blog.csdn.net/wangdianyong/article/details/44157113

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!