Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Count Distinct with Over Partition? Alternatives?

$
0
0

Trying to figure out the best way to get the correct count for these columns. The count will be determined by the number of jobs and orders. I know the numbers growing has something to do with my join since it is counting the jobs and orders by their line items (where the job or order number is repeated). What's the best way to fix this? I tried to use Outer Apply but don't know enough about it and I attempted to use a CASE statement to fix but to no avail.

SQL
SQLSELECTDISTINCTCONVERT(CHAR(10),DATEADD(d,CU10.DAT_CREATED+5843,0),1)AS'DATE ENTERED',CU10.CUST_NAME,CU10.INDUSTRY_CODE,JC17.IND_DESC,COUNT(JC10.JOB_NUMB)OVER(PARTITIONBYJC10.JOB_NUMB)ASJOB_TOTAL,COUNT(OE10.ORD_NUMB)OVER(PARTITIONBYOE10.ORD_NUMB)ASORDER_TOTAL,(SELECTTOP1JC10.DATE_SHIPPEDFROMJC10WHEREJC10.BILLTO_NUMB=CU10.BILLTO_NUMBORDERBYJC10....

Viewing all articles
Browse latest Browse all 4871

Trending Articles