troubleshooting Question

Hello Experts,

I have a query, which returns results from an online survey, the existing query is detailed below -

What I would like to do though is tier the results, so that any suppliers with less that 10% stockists are moved to the bottom, so the results would look like so

Stockists > 10% order by Total Desc

Stockists < 10% order by Total Desc

and have these returned in one recordset as they are currently.

Any suggestions?

Appreciate the help, many thanks

I have a query, which returns results from an online survey, the existing query is detailed below -

```
select
ROW_NUMBER() OVER(order by (((sum(Saleability) + sum(Quality) + sum(Availability) + sum(Delivery) + sum([Returns]) + sum(RetailPrice) + sum(ServiceSupport) + sum(Rep) + sum(Accounts) + sum(CreditControl) ) /10) / count(*)) desc) as Position,
brandid,
B.Name,
/*sum(Saleability) TotalSaleability,*/
sum(Saleability) /count(*) as avgSaleability,
/*sum(Quality) TotalQuality,*/
sum(Quality) /count(*) as avgQuality,
/*sum(Availability) TotalAvailability,*/
sum(Availability) /count(*) as avgAvailability,
/*sum(Delivery) TotalDelivery,*/
sum(Delivery) /count(*) as avgDelivery,
/*sum([Returns]) TotalReturns,*/
sum(Returns) /count(*) as avgReturns,
/*sum(RetailPrice) TotalRetailPrice,*/
sum(RetailPrice) /count(*) as avgRetailPrice,
/*sum(ServiceSupport) TotalServiceSupport,*/
sum(ServiceSupport) /count(*) as avgServiceSupport,
/*sum(Rep) TotalRep,*/
sum(Rep) /count(*) as avgRep,
/*sum(Accounts) TotalAccounts,*/
sum(Accounts) /count(*) as avgAccounts,
/*sum(CreditControl) TotalCreditControl,*/
sum(CreditControl) /count(*) as avgCreditControl,
(((sum(Saleability) + sum(Quality) + sum(Availability) + sum(Delivery) + sum([Returns]) + sum(RetailPrice) + sum(ServiceSupport) + sum(Rep) + sum(Accounts) + sum(CreditControl) ) /10) / count(*)) Total,
count(*) Stockists,
sum(case when nextyeartrade = 'Y' then 1 else 0 end) as StockistsNY
from [dbo].[SupplierSurveyInput] S
inner join dbo.Brand B
on S.BrandID = B.ID
where [CYearStockist] = 'Y'
group by b.name, brandid, SupplierSurveyID
order by Total desc
```

What I would like to do though is tier the results, so that any suppliers with less that 10% stockists are moved to the bottom, so the results would look like so

Stockists > 10% order by Total Desc

Stockists < 10% order by Total Desc

and have these returned in one recordset as they are currently.

Any suggestions?

Appreciate the help, many thanks

Join the community to see this answer!

Join our exclusive community to see this answer & millions of others.

Unlock 1 Answer and 17 Comments.

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert

See if this solution works for you by signing up for a 7 day free trial.

Unlock 1 Answer and 17 Comments.

Try for 7 days”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.