Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Aggregate Function Know-How Needed
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01442673
Message ID:
01442688
Views:
30
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform