The Chinese translation of MySQL MIN() + 1 row is "MySQL minimum value() + 1 row"
P粉564301782
P粉564301782 2023-09-07 16:31:45
0
1
433

I'm running a SELECT query to get data from MySQL

SELECT
    MIN(datetime) as created,
    MAX(datetime) as updated,
    COUNT(CASE WHEN type = 'update' AND contact_name <> 'System' THEN 1 END) as replies,
    COUNT(CASE WHEN type = 'update' AND (contact_name * 1 = contact_name) THEN 1 END) as customer_replies

And it works fine, but I also want to get the next row after MIN(datetime)

Is it possible to do this like MIN() 1?

P粉564301782
P粉564301782

reply all(1)
P粉805535434

Here is a solution that gives the second smallest value:

SELECT
    MIN(datetime) as created_second_minimum 
FROM TableName
ORDER BY datetime
LIMIT 1,1;

When we use LIMIT n, it returns the first n rows, and when we use LIMIT n,m, it returns the m rows after the nth row (excluding the nth row). In our case it doesn't return the first row, only the second row. Since we ordered the query by datetime, the second row is the second oldest.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template