我有4张桌子:
输出如下所示。我有一个主表,它有多个级别存储的项目,还有第二个表可能有也可能没有其他数据。我需要从我的主表中查询两个级别,并在我的另一个表上有一个左连接,但由于我的查询中的排序,这将无效。
hrm_personal_information (PBI_ID,Name,department_id,designation_id)
department (department _id,department _name)
designation(designation_id,designation_name)
access_event_logs(PBI_ID,TIMESTAMPS)
User ID Name Deapartment Designation Date Day In Time Out Time Working Hours
100032 Farid Ahammad Anesthesia Senior Consultant 11/2/2015 Saturday 10:05:01 17:12:02 7:07
100032 Farid Ahammad Anesthesia Senior Consultant 11/3/2015 Sunday 10:10:01 17:30:02 7:30
100032 Farid Ahammad Anesthesia Senior Consultant 0000-00-00 Monday 0:00:00 0:00:00 0:00
100032 Farid Ahammad Anesthesia Senior Consultant 11/5/2015 Tuesday 10:00:01 17:10:02 7:10
100032 Farid Ahammad Anesthesia Senior Consultant 0000-00-00 Wedday 0:00:00 0:00:00 0:00
100032 Farid Ahammad Anesthesia Senior Consultant 11/7/2015 Tharusday 10:05:01 17:05:02 7:00
100032 Farid Ahammad Anesthesia Senior Consultant 11/8/2015 Friday 10:05:01 17:12:02 7:07
我的查询是
SELECT a.PBI_ID as employee_id,
concat(first_name," ",middle_name," ",last_name) as Name, c.DESG_DESC as designation,
b.DEPT_DESC as department,
e.BRANCH_NAME as work_place,
date(TIMESTAMPS) as Date_on,
DAYNAME(TIMESTAMPS) as days,
min(time(TIMESTAMPS)) as in_time, `enter code here`
max(time(TIMESTAMPS)) as out_time,
TIMEDIFF(max(time(TIMESTAMPS)),
min(time(TIMESTAMPS))) as hours,
a.office_start_time as office_hours_from,
a.office_end_time as office_hours_to,
a.office_hours
FROM
hrm_personal_information a,
department b,
designation c,
branch e,
access_event_logs h
WHERE 1 and
a.department = b.DEPT_ID and
a.designation=c.DESG_ID and
a.branch=e.BRANCH_ID and
h.USERID=a.PBI_ID and
h.USERID like "%100032%" and
TIMESTAMPS between "2015-11-01" and
"2016-06-05"
group by DATE(h.TIMESTAMPS)
order by h.TIMESTAMPS