Welcome to Sign in | Help

Re: Select >> Update - SQL Server 2005

  •  01-22-2009, 12:46 PM

    Re: Select >> Update - SQL Server 2005

    SELECT ...
    GROUP BY b.CodContract

    La ce anume se refera acel GROUP BY de la coada? Nu ai nici o functie agregat in select, deci nu ai de ce sa ai GROUP BY

    In general ce vrei tu se face mai usor si mai rapid printr-un self join, nu prin subquery. Asa pe ghicite as zice ca ceva de genul asta:

    select b.CodContract
    from LBF B
    join (select NodId, CodContract, sum(principalpaltit+principalrestant-amendamentprincipal) as sum
     from lbf
     where tipcredit=0
     and datareferinta='12/31/2008'
     group by codcontract
    ) s on b.codcontract=s.codcontract and b.nodid=s.nodid
    where datareferinta='12/31/2008'
    and tipcredit=0
    and b.valoarecontract != s.sum;

    Join-ul poate fi outer join, depinde de ce anume vrei.





    http://rusanu.com
View Complete Thread
Powered by Community Server (Commercial Edition), by Telligent Systems