SELECT name
, SEC_TO_TIME( MAX(TIME_TO_SEC(login_date))
- MIN(TIME_TO_SEC(login_date))
) x
FROM my_table
GROUP
BY name;
How to compare the first date and the last date?
-
27-06-2023 - |
Question
I have this table:
|NAME(Key) | LOGIN_DATE |
|----------------|---------------------|
|mark | 2012-10-10 10:35:00 |
|mark | 2012-10-10 10:40:00 |
|mark | 2012-10-10 10:45:00 |
I want to know how to find the difference between last and first dates:
|NAME | TIME_DIFF |
|----------------|---------------------|
|mark | 10 minutes |
How can I do this?
Solution 2
OTHER TIPS
select
name,
concat( timestampdiff( minute,
min( login_date ),
max( login_date ) ),
' minutes'
) as 'login duration'
from my_table
group by name
SELECT MIN(`LOGIN_DATE`), MAX(`LOGIN_DATE`) WHERE `NAME(Key)` = 'mark';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow