Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grouping
Message
 
 
À
25/04/2002 04:33:14
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Divers
Thread ID:
00649021
Message ID:
00649079
Vues:
15
You've to use the same expression in the GROUP BY clause
select case when month(sanct_dt)<=3 then year(sanct_dt)-1 
       else year(sanct_dt) END as CurFinYear, 
  sum(ttl_amt) from sanctionTable
  GROUP BY case when month(sanct_dt)<=3 then year(sanct_dt)-1 
       else year(sanct_dt) END
Or you can use a derived table
SELECT st.CurFinYear, SUM(st.ttl_amt) 
   FROM (SELECT case when month(sanct_dt)<=3 then year(sanct_dt)-1 
       else year(sanct_dt) END as CurFinYear, ttl_amt from sanctionTable) ST
  GROUP BY st.CurFinYear
  ORDER BY st.CurFinYear
>hi,
>I'm having a query like
>
>select case when month(sanct_dt)<=3 then year(sanct_dt)-1 
       else year(sanct_dt) as CurFinYear, sum(ttl_amt) from sanctionTable
>the basic idea is to get the financial year for the sanction date based on the month and total the amount grouped on CurFinYear.
>
>I can't give CurFinYear in group by as it gives invalid col name error
>
>how to group the above sql ??? any other way is possible ?
>
>TIA
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform