I have a table that look like this:

我有一个看起来像这样的表:

The result that I need is which empid that their passportno has been changed by user='12345'. empid is employee ID and userid is HR Personnel.

我需要的结果是,他们的passportno已被user ='12345'更改。 empid是员工ID,userid是HR Personnel。

This is my query:

这是我的查询:

SELECT * FROM audit_is_emppersonal
WHERE date between '09/25/2017' and 
'12/12/2017' 
 and userid='12345'

**update

This is my expected result:

这是我的预期结果:

As u can see, it only appear empid that passportno has been changed by userid='12345'

正如你所看到的那样,只有用户名='12345'才能改变passportno

4 个解决方案

#1


0

From what you are showing it seems you always have two records for one date, one with action 'BEFORE UPD', one with action 'AFTER UPD' and you want to see when passwordno was changed in such a process.

根据你所显示的内容,你似乎总是有一个日期的两条记录,一条带有动作'BEFORE UPD',一条带有动作'AFTER UPD',你想知道在这样的过程中何时更改了passwordno。

select
  bu.userid,
  bu.date,
  bu.empid,
  bu.passportno as passportno_before_update,
  au.passportno as passportno_after_update
from (select * from audit_is_emppersonal where action = 'BEFORE UPD') bu
join (select * from audit_is_emppersonal where action = 'AFTER UPD') au
  on  au.userid     =  bu.userid 
  and au.empid      =  bu.empid
  and au.date       =  bu.date 
  and au.passportno <> bu.passportno
where bu.userid = 12345
  and bu.date between '20170925' and '20171212';

(You may have to adjust the ON clause slightly according to what must match exactly to identify two records for the same update.)

(您可能必须根据必须完全匹配的内容稍微调整ON子句,以便为同一更新标识两个记录。)

更多相关文章

  1. HSQLDB / Oracle - IN子句中的1000多个项目
  2. 在JComboBox箭头JButton上附加动作事件

随机推荐

  1. android 中SoundPool总结
  2. Android 自定义View自定义属性的声明
  3. android 学习笔记(一):1 环境搭建
  4. android 的webview调用php服务器js , js
  5. Android事件分发机制 详解攻略
  6. Android控件布局常用属性
  7. Android Telephony框架结构简析
  8. Android 面试必备 - 线程
  9. Android中实现全屏、无标题栏的两种办法(
  10. Android 远程调试 JNI 实现 ( Android JNI