Reputation: 33
I want to ask about query, I want to make last insert item system.
If some people insert new item, I will insert date and time to the track
table
and then, I want to get the first and last rows of the day per date:
What query to get like that data?
Upvotes: 0
Views: 73
Reputation: 17925
I think the first column is harder in MySQL but I can give you the rest. Do you really need to number the output rows that way?
select
Employee_ID, `date`,
min(Insert_date_time) as First_Time, max(Insert_date_time) as Last_Time
from track
group by Employee_ID, `date`
Upvotes: 1
Reputation: 311893
A simple group by
clause should do the trick:
SELECT employee_id,
`date`,
MIN(insert_data_time) AS first_time,
MAX(insert_data_time) AS last_time
FROM track
GROUP BY employee_id, `date`
Upvotes: 1