jkrasnay / sqlbuilder

SQL Builder Library for Java
Apache License 2.0
252 stars 73 forks source link

how to build left join sql? #11

Closed victorsheng closed 6 years ago

victorsheng commented 7 years ago

how to build left join sql? like this: select stat_sale_order_detail.* from stat_sale_order_detail inner join( SELECT warehouse_id, sku_id, tenant_id, number from stat_stock where number> 3 and number< 5 and pt= '20171020' ) first_stock on stat_sale_order_detail.sku_id= first_stock.sku_id and stat_sale_order_detail.warehouse_id= first_stock.warehouse_id and stat_sale_order_detail.tenant_id= first_stock.tenant_id inner join( SELECT warehouse_id, sku_id, tenant_id, number from stat_stock where number> 3 and number< 5 and pt= '20171025' ) lastest_stock on stat_sale_order_detail.sku_id= lastest_stock.sku_id and stat_sale_order_detail.warehouse_id= lastest_stock.warehouse_id and stat_sale_order_detail.tenant_id= lastest_stock.tenant_id inner join sku on stat_sale_order_detail.sku_id=sku.sku_id and sku.sku_no ='ZZ-202-006L' where 1=1 limit 10

  1. how to join left join
  2. how to add left join condition on ,like this'on stat_sale_order_detail.sku_id=sku.sku_id and sku.sku_no ='ZZ-202-006L' '
jkrasnay commented 7 years ago

Hey victorsheng,

Left joins are done with the SelectCreator.leftJoin(String) method. The join/leftJoin methods just take a String. You have to build the joined clause yourself. jk

On Sun, Oct 29, 2017, at 11:41 PM, victorsheng wrote:

how to build left join sql? like this: select stat_sale_order_detail.* from stat_sale_order_detail inner join( SELECT warehouse_id, sku_id, tenant_id, number from stat_stock where number> 3 and number< 5 and pt= '20171020' ) first_stock on stat_sale_order_detail.sku_id= first_stock.sku_id> and stat_sale_order_detail.warehouse_id= first_stock.warehouse_id and stat_sale_order_detail.tenant_id= first_stock.tenant_id inner join(> SELECT warehouse_id, sku_id, tenant_id, number from stat_stock where number> 3 and number< 5 and pt= '20171025' ) lastest_stock on stat_sale_order_detail.sku_id= lastest_stock.sku_id> and stat_sale_order_detail.warehouse_id= lastest_stock.warehouse_id and stat_sale_order_detail.tenant_id= lastest_stock.tenant_id inner join sku on stat_sale_order_detail.sku_id=sku.sku_id and sku.sku_no ='ZZ-202-006L'> where 1=1 limit 10

  1. how to join left join
  2. how to add left join condition on ,like this'on stat_sale_order_detail.sku_id=sku.sku_id and sku.sku_no ='ZZ-202- 006L' '> — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub[1], or mute the thread[2].>

Links:

  1. https://github.com/jkrasnay/sqlbuilder/issues/11
  2. https://github.com/notifications/unsubscribe-auth/AAKhlS7sq-kJgVstT9PbyGLKerNuKMbuks5sxUVmgaJpZM4QKoz3
victorsheng commented 7 years ago

3Q~