如何在SQL中获取记录数量

时间:2022-06-02 22:15:05

I am having 25 Lacs records in table , how can i get first 10 lacs after 10 lacs and after that 5 lacs records in sql Server 2008.

我在表中有25条Lacs记录,如何在sql Server 2008中,在10条Lacs记录之后得到前10条Lacs记录。

Could you please help me in this?

你能帮我个忙吗?

In PL SQL i do like this

在PL SQL中,我喜欢这样

SELECT * FROM temp WHERE rownum > or rownum < 10

Please suggest.

请建议。

2 个解决方案

#1


4  

SELECT * FROM 
(
SELECT ROW_NUMBER() OVER (ORDER BY [dataKeyColumnName]) AS RowNo, * FROM Temp 
) AS A
WHERE A.RowNo BETWEEN 10 AND 15

#2


1  

It depends on the DB that you use.

这取决于你使用的DB。

For Oracle you can use

对于Oracle,您可以使用

SELECT * FROM(
   SELECT ROW_NUMBER() OVER (ORDER BY [tableId]) AS RowNr, * FROM MyTable 
) AS T
WHERE T.RowNr BETWEEN 6 AND 15

See also the discussion : LIMIT / OFFSET in Oracle 11G

请参见Oracle 11G中的极限/偏移

For MYSQL you can use

对于MYSQL,您可以使用

SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15

#1


4  

SELECT * FROM 
(
SELECT ROW_NUMBER() OVER (ORDER BY [dataKeyColumnName]) AS RowNo, * FROM Temp 
) AS A
WHERE A.RowNo BETWEEN 10 AND 15

#2


1  

It depends on the DB that you use.

这取决于你使用的DB。

For Oracle you can use

对于Oracle,您可以使用

SELECT * FROM(
   SELECT ROW_NUMBER() OVER (ORDER BY [tableId]) AS RowNr, * FROM MyTable 
) AS T
WHERE T.RowNr BETWEEN 6 AND 15

See also the discussion : LIMIT / OFFSET in Oracle 11G

请参见Oracle 11G中的极限/偏移

For MYSQL you can use

对于MYSQL,您可以使用

SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15