Hey guys
i need some help with sampling data
Please see my query below
Please find attached screen print of the results once the query has been excuted
However i have an issue, as you can see from my screen print i have multiple 2m- 4m accounts. I want to assign these '2M to 4M' equally between two people.
For eg, if there is 100accounts within the '2M to 4M', i want 50 of those accounts to go to seller r14 and the others to go to r15.
Can anyone help me with this
SELECT sub.*,
case when SalesBandRM = '2M to 4M'
and MCC_Code not in ('7997','7941') then 'R14'
when fdmsaccountno IN ('878177270880','878030700883','878231021881','878 233596880','878970059886','878970013883') OR MCC_Code in ('7997','7941')
then 'R05'
else RMSC end as RMSC
FROM
(SELECT
[DBA_Name],
o.[fdmsaccountno],
[ho],
sum ([Gross_Sales]) as Sales,
dbo.salesbandRM(sum(Gross_Sales))as SalesBandRM,
[post_code],
[Open_Date],
CASE
WHEN Isnumeric(RIGHT(LEFT(post_code, 2), 1)) = '0' THEN
LEFT(post_code, 2)
ELSE LEFT(post_code, 1)
END AS 'sPostcode',
[mcc_code]
From [FDMS].[dbo].[Fact_Financial_History_Annualised] f
inner join Dim_Outlet o
on f.FDMSAccountNo = o.FDMSAccountNo
WHERE [rm_sales_band]IN ( '2M to 4m', '4m +' )
AND [ho] = 'Y'
and Account_Status = '16'
and LBG_Status <> 'Accepted'
AND iso_account = 'N'
AND Open_Date < dateadd(mm, -3, getdate())
and Agent_Chain_No not in ('878970059886', '878970013883')
AND o.fdmsaccountno NOT IN (SELECT [ta_mid]
FROM
fdms_partnerreporting.tmp.trade_assocations)
group by
[DBA_Name],
o.[fdmsaccountno],
[ho],
[post_code],
[Open_Date],
[MCC_Code]
) Sub
INNER JOIN [geo_pca_sellers]
ON [pca] = spostcode
order by DBA_Name
i need some help with sampling data
Please see my query below
Please find attached screen print of the results once the query has been excuted
However i have an issue, as you can see from my screen print i have multiple 2m- 4m accounts. I want to assign these '2M to 4M' equally between two people.
For eg, if there is 100accounts within the '2M to 4M', i want 50 of those accounts to go to seller r14 and the others to go to r15.
Can anyone help me with this
SELECT sub.*,
case when SalesBandRM = '2M to 4M'
and MCC_Code not in ('7997','7941') then 'R14'
when fdmsaccountno IN ('878177270880','878030700883','878231021881','878 233596880','878970059886','878970013883') OR MCC_Code in ('7997','7941')
then 'R05'
else RMSC end as RMSC
FROM
(SELECT
[DBA_Name],
o.[fdmsaccountno],
[ho],
sum ([Gross_Sales]) as Sales,
dbo.salesbandRM(sum(Gross_Sales))as SalesBandRM,
[post_code],
[Open_Date],
CASE
WHEN Isnumeric(RIGHT(LEFT(post_code, 2), 1)) = '0' THEN
LEFT(post_code, 2)
ELSE LEFT(post_code, 1)
END AS 'sPostcode',
[mcc_code]
From [FDMS].[dbo].[Fact_Financial_History_Annualised] f
inner join Dim_Outlet o
on f.FDMSAccountNo = o.FDMSAccountNo
WHERE [rm_sales_band]IN ( '2M to 4m', '4m +' )
AND [ho] = 'Y'
and Account_Status = '16'
and LBG_Status <> 'Accepted'
AND iso_account = 'N'
AND Open_Date < dateadd(mm, -3, getdate())
and Agent_Chain_No not in ('878970059886', '878970013883')
AND o.fdmsaccountno NOT IN (SELECT [ta_mid]
FROM
fdms_partnerreporting.tmp.trade_assocations)
group by
[DBA_Name],
o.[fdmsaccountno],
[ho],
[post_code],
[Open_Date],
[MCC_Code]
) Sub
INNER JOIN [geo_pca_sellers]
ON [pca] = spostcode
order by DBA_Name