Sunday, 15 January 2012

sql server 2014 - Trying to use Row over by partition to group data -


I'm trying to get the number of stores every week, which had zero sales of products on sale, but in line I am doing something wrong, more than divisional function.

This is my code:

  IF object_id ('tempdb .. # All', 'U') tap drop table # is not all; IF object_id ('tempdb .. # zero', 'U') is not the tap drop table #oros; # Select [Fiscal YR], [fixed work], [store], [UPCCDED], [Matsuku], [suunites], [problems], [prot.com], description = description in all [scan] [DBO]. [DBO]. [Scan] left left outer [pond] [DBO]. [UMPQA_Dairy_Authorizations] Spcccd on one = A. [UPC] Where Ficariari = '2015' and Decrypton = A Selectwriter *, ROW_NUMBER () Over (By Particular By UPCCDA, RDNR # All by Fiscal WK # Where all the UPCCADA, [FASCISHIAR], [Fixed WQ], [Store] , [Item sq], [suunites], [sumusleus], ​​[prodc], details  by null = 0 group 

now this UPCCD is counting per line, so in the first UPC Row 1-7 and the second row has 1-5 lines. Should I see that this is:

FiscalWk UPCCode #StoresZeroSales 2 48500017753 7 3 48500017753 5

Does anyone Do you know how to do?

You should not use the ROW_NUMBER Select a simple COUNT :

  FiscalWk, UPCCode, COUNT (*) [#StoresZeroSales] # All SumSales = 0 Group by FiscalWk, UPCCode; < / Code> 

No comments:

Post a Comment