in query, only the first few result sets matched by each query

select a.* from table a where 4>(select count(*) from table where id=a.id and id > a.id)
age in (16,17) 
order by a.create_time desc

Replace the table name above, and then modify the result set of each query matching, and modify the sorting rules according to your own business needs. The most important SQL is id > a.idthat the field for comparison must be recognizable , I used create_time before, but the create_time of a lot of data in the table is the same. I only want to fetch the latest 4 pieces of data that are 16 and 17 years old, but the result does not meet expectations, because the create_time field has too much There are more same data, and then I thought that id is self-increasing, and there is no physical deletion, so id can be used for comparison. The larger id must be the data that is later stored, even if the create_time is the same at this time, take more A large id is also logical.

Guess you like

Origin blog.csdn.net/weixin_38106322/article/details/111600588