i have a select query in sql server 2008. It has a more tham million records .It is taking longer time to execute
select ItemCode ,sum(isnull(QtyIn,0)-isnull(QtyOut,0))BalQty from ItemMaster where DocDate <='2023-12-28'
group by ItemCode
This is taking more than 5 mins