mysql - Create self join query -


I am trying to create the attendance system designed for check-in and check-out table below as < / P> (login) (login date) log_type [enum ('I', 'O')] fk_created_id

example record

here I want to check two separate fields and check out so that I can calculate the difference of the day or the total hours of the day.

  7 2014 / 07-31 06:00:32 I 1 8 2014 / 07-31 09:10:32 o 19 2014 / 07-31 09:30:32 I 1 10 2014 / 07-31 12:00:32 o1 I'm trying to create a self-join query but here I do not know which two fields will be compared. How to ask yourself this question? And how to find out in this type of query   

Check it out if you can help < / P>

Please note that the test and examples: Employees and managers here have an employee table from the database

  mysql> Choose from Employee *; + ---- + ------------ + ----------- + ------------ + | ID | First_name | Last_name Manager_id | + ---- + ------------ + ----------- + ------------ + | 1 | Hattie | Hopkins | 4 | | 2 | Henry Hopkins | 4 | | 3 | Harry | Hopkins | 5 | | 4 | Helen Hopkins | Faucet | 5 | Heidi | Hopkins | 4 | | 6 | Hazel | Hopkins | 1 | + ---- + ------------ + ----------- + ------------ + 6 rows in set ( 0.00 seconds)  

In order to get the employees, and then to get names of managers, whom to report, we should ask the table.

  mysql> Select E.first_name as an employee, m.first_name as reports_to - & gt; From Staff E - & gt; E.manager_id = join an internal employee at m.id; + ---------- + ------------ + | Employees | For reports. + ---------- + ------------ + | Hattie | Helen | Henry Helen | Harry | Heidi | | Heidi | Helen | Hazel | Hattie | + ---------- + ------------ + 5 rows set (0.02 seconds)  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -