Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Aggregate Function Know-How Needed
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01442673
Message ID:
01442688
Vues:
29
>>No, but you can also use CTE approach as well.
>>
>>I was also thinking that you may go away with windowing functions, but it doesn't seem to be good for your problem, though we can, of course, if we, for example, wanted to add the first Item info along with the rest.
>
>Can you provide a CTE example if you have time. I'm just beginning with SQL Server 2008. Would it be something like:
>
>
>WITH SalesTots AS
>(
>  select count(invnum) as sales_count 
>  from invitems
>  group by partnum
>)
>SELECT partmast.partnum,
>              partmast.title,
>              partmast.description
>              ISNULL(partstats.emplviews,0) as Part_Views,
>              ISNULL(partstats.intviews,0) as Internet_Bids,
>              ISNULL(salestots.sales_count,0) as sales_count  
>FROM partmast 
>	LEFT OUTER JOIN partstats 
>		ON partmast.partnum=partstats.partnum 
>	LEFT OUTER JOIN SalesTots 
>		ON partmast.partnum=salestots.partnum
>WHERE partmast.partnum='12345' 
>GROUP BY partnum
>ORDER BY partnum
>
Close
;WITH SalesTots AS
>(
>  select PartNum, count(invnum) as sales_count 
>  from invitems
>  group by partnum
>)
>SELECT partmast.partnum,
>              partmast.title,
>              partmast.description
>              ISNULL(partstats.emplviews,0) as Part_Views,
>              ISNULL(partstats.intviews,0) as Internet_Bids,
>              ISNULL(salestots.sales_count,0) as sales_count  
>FROM partmast 
>	LEFT OUTER JOIN partstats 
>		ON partmast.partnum=partstats.partnum 
>	LEFT OUTER JOIN SalesTots 
>		ON partmast.partnum=salestots.partnum
>WHERE partmast.partnum='12345' 
>GROUP BY partnum
>ORDER BY partnum
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform