Let me briefly explain the functional scenario: The data row fields are as follows:
In this table, name has duplicate values Now we need to filter out a list when the type is determined, so that the name is not repeated and the record with the smallest started_at under the same name is found. For example:
The sieve list should be:
It also needs to satisfy that started_at is greater than the current time How should I write such sql? The solution is: Is to use left join itself For example, Finally SELECT s1.NAME, s1.started_at, FROM tbl s1 LEFT JOIN tbl s2 ON s1.`name` = s2.`name` AND s1.started_at > s2.started_at AND s2.started_at > now() WHERE s2.id IS NULL AND s1.started_at > now() AND s1.type = 'online_lecture' ORDER BY s1.NAME, s1.started_at; Does anyone have any better solution? Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: Linux traceroute command usage detailed explanation
>>: Detailed explanation of the pitfalls of mixing npm and cnpm
Object's hasOwnProperty() method returns a Bo...
In daily website maintenance and management, a lo...
Table of contents 1. What is a subquery? 2. Self-...
During the development activity, I encountered a ...
Use the FRAME property to control the style type ...
The key is that the local server does not have wr...
The find command is used to search for files in a...
Table of contents 1. Eclipse configures Tomcat 2....
Scenario: The data in a table needs to be synchro...
Copy code The code is as follows: wmode parameter...
Joint Index The definition of the joint index in ...
Table of contents Show Me The Code Test the effec...
This article mainly introduces the case of Vue en...
Today, I want to write about a "low-tech&quo...
Networks usage tutorial Official website docker-c...