Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with sum query
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00760459
Message ID:
00760461
Vues:
15
This message has been marked as the solution to the initial question of the thread.
You can use your previous select as derived table. See changes below

>I am using a sum and group by in my query to find differences in a total field in a parent table and the child tables.
>
SELECT SUM(td.diff)
  FROM (
>select o.ytotalorder-sum(ar.yamttrans) as diff
>from orders o inner join orderardetail ar on o.uordid=ar.uordid
>where (ar.cartypid='II' or ar.cartypid='IM') 
>  and o.tcreate>='2002-12-18' group by o.uordid,o.ytotalorder
>having o.ytotalorder>sum(ar.yamttrans)
>order by o.uordid 
       ) td
>
>This works fine. It gives me a list of the orders that are out of balance. Now I want to get a grand total of those differences (sum the difference). Is there a way to do it in T-Sql?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform