如何通过列从数据库顺序获取记录

时间:2022-06-01 20:37:07

I have a 50k records are stored in my mysql database. I have to insert 1k records into excel.

我有一个50k的记录存储在我的mysql数据库中。我必须在excel中插入1k记录。

So, I am querying the records using limit 0, 1000 and limit 1000, 1000 like this. I have to get records using order by of a particular column. I can do this by queryinng using order by.

所以,我使用限制0,1000查询记录,并限制1000,1000这样。我必须使用特定列的顺序获取记录。我可以通过queryinng使用order by来做到这一点。

But if I have same order by of a particular column records from 990 to 1030 because of this limit 0, 1000 function these are splitting. but I want to get all order by values into same excel. If limit is increased or decreased by 50 or 100 records it is ok for me.

但是如果我从990到1030的特定列记录具有相同的顺序,因为这个限制0,1000功能这些是分裂。但是我想通过值将所有订单放到同一个excel中。如果限制增加或减少50或100记录,我可以。

Example: Actually I am getting first 1000 records as one query using limit 0, 1000. Agian I am getting next 1000 records by using limit 1000, 1000. If I've a records from 990 to 1050 of a same order by column data beacuse of this limit i am getting first 1000 records in one file and when I query next 1k records from 1000 to 2000 records i am getting. but the records 990 to 1050 of a same order by is divided. I want to get all order by records in one excel. Increase of records per query is ok for me but lesthan 100 records

示例:实际上我使用限制0,1000获得前1000条记录作为一个查询.Agian我通过使用限制1000,1000获得下一个1000条记录。如果我按列数据从990到1050的相同订单的记录beacuse这个限制我在一个文件中获得前1000条记录,当我查询1000条到2000条记录的下一条1k记录时。但是相同顺序的记录990到1050被划分。我希望通过一个excel中的记录获得所有订单。每个查询的记录增加对我来说是好的,但至少有100条记录

2 个解决方案

#1


0  

From the question, it seems that you only want top 1000 records and a value should not get repeated. In this case, you can use distinct clause along with column name.

从这个问题来看,似乎你只需要前1000条记录,而且一个值不应该重复。在这种情况下,您可以使用distinct子句和列名。

#2


0  

Maybe you can do it with this SQL

也许你可以用这个SQL做到这一点

selcect distinct(column) from Table group by column  order by column  limt A ,B 

#1


0  

From the question, it seems that you only want top 1000 records and a value should not get repeated. In this case, you can use distinct clause along with column name.

从这个问题来看,似乎你只需要前1000条记录,而且一个值不应该重复。在这种情况下,您可以使用distinct子句和列名。

#2


0  

Maybe you can do it with this SQL

也许你可以用这个SQL做到这一点

selcect distinct(column) from Table group by column  order by column  limt A ,B