資料庫表級聯查詢

2021-08-07 05:43:31 字數 2553 閱讀 6711

所謂的級聯查詢也就是通過乙個uid 將兩個表進行鏈結起來,你可以獲取另乙個表中的字段資料。

下面列乙個例子和並講解使用:

用的是mybatis框架。

<?xml version="1.0" encoding="utf-8" ?>

l.id as "id",

l.create_by as "createby",

l.create_date as "createdate",

l.update_by as "updateby",

l.update_date as "updatedate",

l.user_id as "userid",

l.credit_rule_id as "creditruleid",

l.type as "type",

l.credit as "credit",

l.experience as "experience",

l.credit_time as "credittime",

l.remarks as "remarks",

l.del_flag as "delflag",

u.system_id as "user.systemid",

u.name as "user.name",

u.phone as "user.phone",

r.code as "creditrule.code",

r.name as "creditrule.name"

left join sys_user c on c.id = l.create_by

join sys_user u on u.id = l.user_id

join credit_rule r on r.id = l.credit_rule_id

select

from credit_log l

where l.del_flag = #

and l.user_id = #

and l.credit_rule_id = #

and l.type = #

and u.system_id = #

and u.phone like concat('%', #, '%')

order by l.credit_time desc

前台顯示資料

使用的時候用的是partner.user.systemid    xml中  u.system_id as "user.systemid"

傳送後台時用的是 systemid    查詢 語句中 :

and u.system_id = #

說明:這個例子就是通過使用者表的id 和 這個合夥人表的 userid 進行鏈結,通過積分表裡面的userid 去查詢使用者表中的支付id

left join sys_user c on c.id = l.create_by

join sys_user u on u.id = l.user_id

join credit_rule r on r.id = l.credit_rule_id

包含語句:

l.tid as "tid",

l.id as "id",

l.create_by as "createby",

l.create_date as "createdate",

l.update_by as "updateby",

l.update_date as "updatedate",

l.user_id as "userid",

l.credit_rule_id as "creditruleid",

l.type as "type",

l.credit as "credit",

l.experience as "experience",

l.credit_time as "credittime",

l.remarks as "remarks",

l.del_flag as "delflag",

u.system_id as "user.systemid",

u.name as "user.name",

u.phone as "user.phone",

r.code as "creditrule.code",

r.name as "creditrule.name"

查詢語句:

select 

from credit_log l

where l.del_flag = #

and l.user_id = #

and l.credit_rule_id = #

and l.type = #

and u.system_id = #

order by l.credit_time desc

sql實現ORACLE 資料庫的級聯查詢

在oracle 資料庫中有使用sql實現級聯查詢 select 要查詢的字段 from table 具有子接點id與父接點id的表 start with selfid id 給定乙個startid 欄位名為子接點id,及開始的id號 connect by prior selfid parentid ...

oracle級聯查詢

今天學習oracle 學到了乙個級聯語句 select from table start with 條件1 connect by prior 條件2 where 條件3例 select from usertable start with parent id 1 connect by prior or...

級聯查詢案例

1.後台查詢所有省份資訊返回省份的list集合 map string,object map new hashmap string,object string jb 1 查詢省會 list provicelist areaservice.queryareabyjb jb map.put provice...