当前位置:网站首页>Oracle query foreign keys contain comma separated data
Oracle query foreign keys contain comma separated data
2022-04-23 03:18:00 【JavaTestZhangy】
Mode one 、 Comma separated fields are converted into rows for association query , When the query result comes out, it will be transferred from row to column and back
Example :
select
--- staff id
T3.id,
-- Employee number
T3.staff_code,
-- user ( Telephone )
T3.phone,
-- full name
T3.staff_name,
-- ID number
T3.USER_IDENTIFICATION,
T3.EMAIL,
T3.phone,
T3.QQ,
T3.WCHAT,
-- Position code
listagg (T3.post_code, ',')
WITHIN GROUP (ORDER BY T3.post_code)post_code,
-- Job title
listagg (T3.post_name, ',')
WITHIN GROUP (ORDER BY T3.post_name)post_name,
-- Furniture consultant code
sg.guide_code,
-- Furniture Consultant
sg.guide_name,
-- Dealer code
busines.business_code,
-- Store code
T3.shop_code,
-- Administrator or not
T3.IS_BUSINESS_ADMIN,
-- Tenant id
T3.TENANT_ID,
-- state
T3.states,
-- Creation time
to_char(T3.create_time,'yyyy-mm-dd hh24:mi:ss'),
-- Last modified
to_char(T3.last_modified_time,'yyyy-mm-dd hh24:mi:ss')
from(
select u.id,
t1.TENANT_ID,
t1.staff_code,
u.phone,
t1.staff_name,
t1.USER_IDENTIFICATION,
t2.post_code,
t2.post_name,
t1.EMAIL,
t1.QQ,
t1.WCHAT,
t1.IS_BUSINESS_ADMIN,
u.states,
shop.code shop_code,
t1.create_time,
t1.last_modified_time,
t1.shopping_guide_user_type
from
fplatform.app_user u
inner join
(
select
a.*,
REGEXP_SUBSTR(a.post_id ,'[^,]+',1,l) post_id2
from
fplatform.T_BSC_STAFF a,
(SELECT LEVEL l FROM DUAL CONNECT BY LEVEL<=100) b
WHERE l <=LENGTH(a.post_id) - LENGTH(REPLACE(post_id,','))+1
--and a.tenant_id='7eba602b271c49aba395a1fc264824af' and a.phone='18899998888'
and a.del_status=0
-- Enable
--and a.IS_ONLINE=1
order by a.staff_name
)t1
on t1.PLATFORM_ID=u.id
left join fplatform.T_BSC_STAFF_POST t2
on t1.post_id2 = t2.id
--inner join fplatform.app_user u
-- on t1.PLATFORM_ID=u.id
left join MPLATFORM.BASE_SHOP shop
on t1.STORE_ID=shop.id
where u.states=1
)T3
left join fplatform.T_BSC_STAFF_GUIDE sg
on T3.shopping_guide_user_type=sg.id
left join fplatform.t_business_archives busines
on T3.TENANT_ID=busines.id
group by
T3.id,
T3.TENANT_ID,
T3.staff_code,
T3.phone,
T3.staff_name,
T3.USER_IDENTIFICATION,
T3.EMAIL,
T3.phone,
T3.QQ,
T3.WCHAT,
sg.guide_code,
sg.guide_name,
busines.business_code,
T3.shop_code,
T3.IS_BUSINESS_ADMIN,
T3.states,
T3.create_time,
T3.last_modified_time
Mode two 、 Comma separated fields are written directly when there are few associated foreign keys case wen Judge
Example :
select
--- staff id
t2.id,
-- Employee number
t1.staff_code,
-- user ( Telephone )
t2.phone,
-- full name
t1.staff_name,
-- ID number
t1.USER_IDENTIFICATION,
t1.EMAIL,
t1.phone,
t1.QQ,
t1.WCHAT,
-- Position code
CASE WHEN instr(t1.post_name,' business ')>0 THEN '01,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Warehouse management ')>0 THEN '02,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Home Consultant ')>0 THEN '03,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Shopowner ')>0 THEN '04,' ELSE ''END||
CASE WHEN instr(t1.post_name,' The front desk ')>0 THEN '05,' ELSE ''END||
CASE WHEN instr(t1.post_name,' accounting ')>0 THEN '06,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Cashier ')>0 THEN '07,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Installation technician ')>0 THEN '08,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Service Technician ')>0 THEN '09,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Delivery personnel ')>0 THEN '10,' ELSE ''END||
CASE WHEN instr(t1.post_name,' after-sales ')>0 THEN '11,' ELSE ''END||
CASE WHEN instr(t1.post_name,' The designer ')>0 THEN '12,' ELSE ''END||
CASE WHEN instr(t1.post_name,' The manager ')>0 THEN '13,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Marketing Specialist ')>0 THEN '14,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Design Director ')>0 THEN '15,' ELSE ''END||
CASE WHEN instr(t1.post_name,' Customized business counterpart ')>0 THEN '16,' ELSE ''END
as post_code,
-- Job title
t1.post_name,
-- Furniture consultant code
t4.guide_code,
-- Furniture Consultant
t4.guide_name,
-- Dealer code
t5.business_code,
-- Store code
t3.code shop_code,
-- Administrator or not
t1.IS_BUSINESS_ADMIN,
-- Tenant id
t1.TENANT_ID,
-- state
t2.states,
-- Creation time
to_char(t1.create_time,'yyyy-mm-dd hh24:mi:ss') create_time,
-- Last modified
to_char(t1.last_modified_time,'yyyy-mm-dd hh24:mi:ss') last_modified_time
from
fplatform.T_BSC_STAFF t1
inner join fplatform.app_user t2
on t1.PLATFORM_ID=t2.id
left join MPLATFORM.BASE_SHOP t3
on t1.STORE_ID=t3.id
left join fplatform.T_BSC_STAFF_GUIDE t4
on T1.shopping_guide_user_type=t4.id
left join fplatform.t_business_archives t5
on t1.TENANT_ID=t5.id
where t2.states=1
版权声明
本文为[JavaTestZhangy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230314477075.html
边栏推荐
- How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
- Docker拉取mysql并连接
- Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
- Eight elder brothers chronicle [4]
- 編碼電機PID調試(速度環|比特置環|跟隨)
- New ORM framework -- Introduction to beetlsql
- 可以接收多種數據類型參數——可變參數
- JS inheritance
- Use of ADB command [1]
- Configuration table and page information automatically generate curd operation page
猜你喜欢
ASP. Net 6 middleware series - execution sequence
PID debugging of coding motor (speed loop | position loop | follow)
Experiment 6 input / output stream
《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
《C语言程序设计》(谭浩强第五版) 第8章 善于利用指针 习题解析与答案
Configuration table and page information automatically generate curd operation page
Utgard connection opcserver reported an error caused by: org jinterop. dcom. common. JIRuntimeException: Access is denied. [0x800
2022山东省安全员C证上岗证题库及在线模拟考试
Use of ADB command [1]
随机推荐
PID debugging of coding motor (speed loop | position loop | follow)
Comprehensive calculation of employee information
Aspnetcore configuration multi environment log4net configuration file
《C语言程序设计》(谭浩强第五版) 第9章 用户自己建立数据类型 习题解析与答案
How does Microsoft solve the problem of multiple PC programs
General test technology [II] test method
【VS Code】解决jupyter文件在vs code中显示异常的问题
Fundamentals of software testing and development
ThreadLocal 测试多线程变量实例
Iotos IOT middle platform is connected to the access control system of isecure center
【无标题】
编码电机PID调试(速度环|位置环|跟随)
Course design of Database Principle -- material distribution management system
Find the number of leaf nodes of binary tree
This new feature of C 11, I would like to call it the strongest!
Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
poi根据数据创建导出excel
Use of slice grammar sugar in C #
JSON related
在.NE6 WebApi中使用分布式缓存Redis