ExpandedVenture / ConnectionSphere

Simple Service to Start Prospecting Online
0 stars 0 forks source link

Query Timeout on Financial Report #261

Open leandrosardi opened 2 years ago

leandrosardi commented 2 years ago
SELECT w.* FROM (   
    SELECT ROW_NUMBER() OVER ( ORDER BY v.y, v.m, v.d, v.type ) AS n, v.*   
    FROM (      
        select  
            year(m.create_time) as y,   
            month(m.create_time) as m,  
            day(m.create_time) as d,    
            m.product_code,     
            m.type,     
            m.id,   
            cast(m.description as varchar(8000)) as description,    
            isnull(m.paypal1_amount,0) as paypal1_amount,   
            isnull(m.bonus_amount,0) as bonus_amount,   
            isnull(m.profits_amount,0) as profits_amount,   
            isnull(m.amount,0) as amount,   
            isnull(m.credits,0) as credits 
        from movement m with (nolock) 
        where m.id_client='AB8B70EF-0FE9-4A37-962D-F6CFE1879EC3' 
        and m.product_code='drx' 
        and m.create_time >= dateadd(MM, -3, getdate()) 
    ) AS v 
) AS w 
WHERE w.n > 0 
AND w.n <= 25