Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL Tuning for 50 million rows--- Group by

$
0
0

For example i have 50 million+ rows in a table with columns Customer_ID, Order_ID and trans_date. I need a query to return customers with more than 2 orders over the past 60 days.

Select customer_id from table
where trans_date between sysdate-60 and sysdate
group by customer_id
having count(customer_id)>=2

I am trying to understand if there is fastest alternative for group by and having. Especially for large data sets. Thanks in advance for your help/suggestions.


svk


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>