1
I have the following query:
The question is as follows. In this table there are several interactions of several users in the same transaction. What I need is to take the last user’s duration time in the transaction.
For example:
According to the above table, the idusers 560049 was the last user to fulfill the transaction. He started the service 2018-09-12T09:34:50Z and ended the service 2018-09-12T09:54:50Z. The service time in this case is 20 minutes.
What matters to me is always the last user of the transaction.
If I try to put min and max gives problem because it groups and gets wrong.
And if it is the case that the user does not have an end time, I just want to ignore it. As in the example below:
I know the question is complex, but I couldn’t explain it any other way. Should any moderator find it unclear, let me know.
A
ORDER BY
withLIMIT 1
would not solve?select * from obusuario
order by created desc limit 1
?– rbz
No, because I need to take the attendance time. That is, the first insertion and the last. :)
– Layla Comparin
Try it this way:
SELECT idusers, MIN(created), MAX(created)
FROM obusuario
WHERE idusers IN (SELECT idusers FROM obusuario
ORDER BY created DESC LIMIT 1)
– rbz
Gave this error: com.mysql.jdbc.exceptions.jdbc4.Mysqlsyntaxerrorexception: This version of Mysql doesn’t yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
– Layla Comparin
Run in your bank? Because fiddle is LIMIT locked in subquery
– rbz
Yes, it was in my bank. I am using dbeaver. And I need that information to be displayed in the Tabase bi, and gave the same error there tbm. :(
– Layla Comparin