Skip to content
Advertisement

Select all rows and ignore the first row

I’m currently using the following SQL query which is returning 25 rows. How can I modify it to ignore the first row:

SELECT fiscal_year, SUM(total_sales) as sum_of_year, AVG(SUM(total_sales)) 
OVER () as avg_sum 
FROM sales_report 
GROUP BY fiscal_year 
ORDER BY fiscal_year ASC

I’m using SQL Server 2008.

Thanks.

Advertisement

Answer

You can use EXCEPT in SQL Server 2008.

SELECT fiscal_year, SUM(total_sales) as sum_of_year, AVG(SUM(total_sales)) 
OVER () as avg_sum 
FROM sales_report 
GROUP BY fiscal_year

EXCEPT

SELECT TOP 1 fiscal_year, SUM(total_sales) as sum_of_year, AVG(SUM(total_sales)) 
OVER () as avg_sum 
FROM sales_report 
GROUP BY fiscal_year 
ORDER BY fiscal_year ASC

For SQL Server 2012 and above, you can use FETCH OFFSET

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement