如何使用Presenty获取员工姓名 [英] How Do I Get Employee Name With Presenty

查看:84
本文介绍了如何使用Presenty获取员工姓名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表格

employee_master

 emp_id emp_name状态createddate由updateddate创建更新由
1 Kiran 1 2015-11- 13 1 2015-11-13 1
2 Praju 1 2015-11-13 1 2015-11-13 1
3 e 0 2015-11-13 1 2015-11-13 1
4 Amol 1 2015-11-13 1 2015-11-13 1
5 Kanchan1 1 2015-11-14 1 2015-11-14 1
6 Archana 1 2015-11-18 1 2015-11 -18 1





attendance_master

 att_id emp_id today_date presenty plant_id 
1 2 2015-11-26 A 2
17 1 2015-11-26 H 1
18 4 2015-11-26 P 1





如果我搜索2015-11-26然后我应该获得

 emp_id emp_name presenty 
1 Kiran H
5 Kanchan1
6 Archana





AND

如果我搜索2015年-11-27然后我应该得到

 emp_id emp_name presenty 
1 Kiran
2 Praju
4 Amol
5 Kanchan1
6 Archana





我的查询是:



SELECT employee_master.emp_id,employee_master.emp_name,IFNULL(attendance_master.presenty,'')AS presenty,attendance_master.today_date

FROM employee_master LEFT JOIN attendance_master ON attendance_master.emp_id = employee_master.emp_id

WHERE employee_master.Status = 1 AND

attendance_master.today_date ='2015-11-26'



代码块添加 - OriginalGriff [/ edit]

解决方案

根据您提供的数据,您的预期结果完全错误



如果您使用2015-11-26运行查询,那么只有3个在该日期的attendance_master上的条目:

 emp_id emp_name presenty today_date 
1 Kiran H 2015-11-26
2 Praju A 2015-11- 26
4 Amol P 2015-11-26



Kanchan1和Archana在attendance_master中没有任何记录 - 任何日期。



如果您运行2015-11-27的查询,那么您将得不到任何内容 - 从您提供的数据 - 因为该日期根本没有任何记录。但是取消了日期检查,你会更接近你期望的结果。



换句话说,你的查询工作正常。



以下文章可能有用 SQL连接的可视化表示 [ ^


I have 2 TABLES
employee_master

emp_id  emp_name    STATUS  createddate createdby   updateddate updatedby
1       Kiran       1       2015-11-13  1           2015-11-13  1
2       Praju       1       2015-11-13  1           2015-11-13  1
3       e           0       2015-11-13  1           2015-11-13  1
4       Amol        1       2015-11-13  1           2015-11-13  1
5       Kanchan1    1       2015-11-14  1           2015-11-14  1
6       Archana     1       2015-11-18  1           2015-11-18  1



attendance_master

att_id  emp_id  today_date  presenty    plant_id
1       2       2015-11-26  A           2
17      1       2015-11-26  H           1
18      4       2015-11-26  P           1



IF i search FOR 2015-11-26 THEN i should get

emp_id  emp_name    presenty
1       Kiran       H
5       Kanchan1    
6       Archana  



AND
IF i search FOR 2015-11-27 THEN i should get

emp_id  emp_name    presenty
1       Kiran
2       Praju
4       Amol
5       Kanchan1
6       Archana



My QUERY IS :

SELECT employee_master.emp_id,employee_master.emp_name,IFNULL(attendance_master.presenty,'') AS presenty,attendance_master.today_date
FROM employee_master LEFT JOIN attendance_master ON attendance_master.emp_id=employee_master.emp_id
WHERE employee_master.Status=1 AND
attendance_master.today_date='2015-11-26'

[edit]Code block added - OriginalGriff[/edit]

解决方案

Your expected results are completely wrong given the data you have presented

If you run your query with 2015-11-26 then there are only 3 entries on attendance_master for that date:

emp_id emp_name presenty today_date
1      Kiran    H        2015-11-26
2      Praju    A        2015-11-26
4      Amol     P        2015-11-26


Kanchan1 and Archana do not have any records in attendance_master - for any date.

If you run the query for 2015-11-27 then you will get nothing - from the data you have presented - as there are no records at all for that date. Remove the check on date however and you get closer to the results you expect.

In other words, your query is working fine.

The following article may be of use Visual Representation of SQL Joins[^]


这篇关于如何使用Presenty获取员工姓名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆