如何获取emp_v和employees有相同的数据no

本文介绍了一种SQL查询技巧,通过使用INTERSECT关键字来找出两个视图中相同的数据记录。具体示例展示了如何从employees表和emp_v视图中获取相同的员工信息。

题目描述

存在如下的视图:
create view emp_v as select * from employees where emp_no >10005;
如何获取emp_v和employees有相同的数据?
CREATE TABLE `employees` (
`emp_no` int(11) NOT NULL,
`birth_date` date NOT NULL,
`first_name` varchar(14) NOT NULL,
`last_name` varchar(16) NOT NULL,
`gender` char(1) NOT NULL,
`hire_date` date NOT NULL,
PRIMARY KEY (`emp_no`));
输出格式:
emp_nobirth_datefirst_namelast_namegenderhire_date
100061953-04-20AnnekePreusigF1989-06-02
100071957-05-23TzvetanZielinskiF1989-02-10
100081958-02-19SaniyaKalloufiM1994-09-15
100091952-04-19SumantPeacF1985-02-18
100101963-06-01DuangkaewPiveteauF1989-08-24
100111953-11-07MarySluisF1990-01-22
代码:
select * from employees intersect select * from emp_v
intersect为产生交集
-- 修数演练执行日志信息 select to_char(t.exec_time, 'yyyy-mm-dd hh24:mi:ss') as etime, t.* from t_datachange_execption_sql_log t order by t.exec_time desc; -- 查询包执行日志 select to_char(t.exec_date, 'yyyy-mm-dd hh24:mi:ss') as etime, t.* from omp_debuginfo_t t where upper(t.proc_name) like '%SYN_AUTOCLEAN_SP%' order by t.exec_date desc; -- 查询DB Job执行结果 select p.what, j.job_id, j.start_date, j.last_start_date, j.last_end_date, j.next_run_date, j.failure_msg from pg_job j left join pg_job_proc p on j.job_id = p.job_id order by j.start_date desc; -- 查询流程审批日志信息 select to_char(t.creation_date, 'yyyy-mm-dd hh24:mi:ss') as cdate, (select lname from tpl_user_t u where u.user_id = t.created_by) as cby, t.* from omp_workflow_log_t t where t.workflow_no in ('W20230504023N') order by t.workflow_no, t.creation_date; -- 查询立项操作日志 select to_char(creation_date) as cdate, t.* from omp_project_operationrecirds_t t where t.project_no = 'W20250415075N' order by t.creation_date desc; -- 查询分摊编码失效检测结果记录 select t.*, to_char(t.last_update_date, 'yyyy-mm-dd hh24:mi:ss') as ldate from omp_profit_share_invalid_t t where t.invalid_code = '069900'; -- 查询应用号推送记录 select to_char(t.creation_date, 'yyyy-mm-dd hh24:mi:ss') as cdate, t.* from omp_message_push_log_t t where t.to_user_account = 's00123123' and t.creation_date > date'2025-06-11'; select to_char(t.creation_date, 'yyyy-mm-dd hh24:mi:ss') as cdate, t.* from omp_message_push_log_t t where t.creation_date > date'2025-07-11' and t.content like '%TRP202507110003%'; -- 查询系统日志(很卡,需要设置好条件) -- M_REFUND -- M_EXPENSE_PAY -- M_EMP_ENTRY_PROJECT -- M_FRAME_PO -- M_TM_REWARD -- M_REGIONAL -- M_PCB -- M_TRIP -- M_EBUY -- M_TM_REWARD_PAY -- M_REVIEW -- M_DISPATCH -- M_TM_PAYMENT -- M_USER_CONF -- M_COOP -- M_PROJECT -- M_BUDGET select to_char(t.creation_date, 'yyyy-mm-dd hh24:mi:ss') as cdate, t.* from omp_log_events_t t where t.creation_date > to_date('2030-04-29 16:40:41', 'yyyy-mm-dd hh24:mi:ss') and t.creation_date < to_date('2024-04-29 16:57:41', 'yyyy-mm-dd hh24:mi:ss'); -- 查询指定人员的历史日志信息 select to_char(al.last_update_date, 'yyyy-mm-dd hh24:mi:ss') as 最后更新时间, (select lname from tpl_user_t where user_id = al.last_updated_by) as 操作人, to_char(al.dimission_date, 'yyyy-mm-dd hh24:mi:ss') as 离司时间, to_char(al.min_entry_project_date, 'yyyy-mm-dd hh24:mi:ss') as 最小入项时间, to_char(al.entry_project_date, 'yyyy-mm-dd hh24:mi:ss') as 入项时间, al.emp_workid, al.log_remark as 日志备注, al.hw_position as 职级, al.emp_state as 人员状态, ecul.emp_name as 姓名, ecul.emp_number as 外包服务编号, c.abbr_name as 供应商, ecul.vendor_code as 供应商编码, p.project_no as 项目编号, p.po_num as PO编号, to_char(sd.service_duration_begin_date, 'yyyy-mm-dd hh24:mi:ss') as 服务时长开始时间, to_char(sd.service_duration_end_date, 'yyyy-mm-dd hh24:mi:ss') as 服务时长结束时间, sd.service_duration as 服务时长, sd.execute_service_duration as 执行类服务时长, ecul.emp_employee_id as 外包合作人员表主键, al.activity_id as 人力大表主键, al.activity_log_id as 人力大表日志表主键 from omp_emp_activity_log_t al left join omp_emp_cooperate_user_log_t ecul on ecul.emp_employee_log_id = al.emp_employee_log_id left join omp_coop_t c on c.status = 'ACTIVE' and c.code = ecul.vendor_code left join omp_project_prpo_info_query_v p on p.entrust_order_id = al.entrust_order_id left join omp_emp_service_duration_t sd on sd.emp_employee_id = ecul.emp_employee_id where ecul.emp_number = 'WB123123' and al.emp_workid like '60032453%' order by ecul.emp_number, al.last_update_date desc; select to_char(t.operate_date, 'yyyy-mm-dd hh24:mi:ss') as odate, (select lname from tpl_user_t u where u.user_id = t.operate_user_id) as operate_user_name, t.* from omp_emp_resource_log_t t left join omp_emp_cooperate_user_t u on u.emp_employee_id = t.emp_employee_id where u.emp_number = 'WB084603' order by t.operate_date desc; select emp_workid, emp_state, emp_name, emp_position, emp_university_name, emp_speciality, emp_role, emp_sub_role, emp_skill, birthday, title from omp_activity_query_t where entrust_order_id = '9eeb3d8876d020800ed56f9c3b8fc630' and emp_state = 3 order by birthday desc; -- 查询人员日志 select to_char(t.operate_date, 'yyyy-mm-dd hh24:mi:ss') as odate, t.* from omp_emp_hr_log_t t left join omp_emp_cooperate_user_t u on u.emp_employee_id = t.emp_employee_id where u.emp_number = 'WB178015' order by t.operate_date desc; select to_char(t.operate_date, 'yyyy-mm-dd hh24:mi:ss') as odate, t.* from omp_emp_resource_log_t t left join omp_emp_cooperate_user_t u on u.emp_employee_id = t.emp_employee_id where u.emp_number = 'WB178015' order by t.operate_date desc; select * from omp_leave_query_t t where t.leave_project_employees like '%王文炳%'; select * from omp_entry_query_t t where t.entry_employees like '%王文炳%'; 帮我整理下,上面脚本的排版,并适当的添加注释
最新发布
10-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值