Subject | how to do a view (or work with) of top 80000 records |
---|---|
Author | Gary Benade |
Post date | 2005-06-22T17:48:21Z |
I have a table with approx 1 million customers, and each customer has a
value based on a weighted scale. Most of the time I want to work with the
top 80000 customers for distribution reasons.
what I want is this
CREATE VIEW V_TOPCUST
AS
select first 80000 *
from customers
order by weighted_value desc
but it doesnt work.
The following logic works, but bogs the server down for hours
select b.name, count(*)
from customers c
join branches b on b.orderappend = c.branchcode and b.enabled = 'T'
where c.deleted = 'N'
and c.link in (select first 80000 link from customers order by
weighted_Value desc)
group by 1
order by b.name
I almost thought this would work too, but its not valid sql
select first 80000 b.name, count(*)
from customers c
join branches b on b.orderappend = c.branchcode and b.enabled = 'T'
where c.deleted = 'N'
group by 1
order by c.weighted_value, b.name
any ideas on other more efficent ways to get this done would be greatly
appreciated.
TIA
Gary
value based on a weighted scale. Most of the time I want to work with the
top 80000 customers for distribution reasons.
what I want is this
CREATE VIEW V_TOPCUST
AS
select first 80000 *
from customers
order by weighted_value desc
but it doesnt work.
The following logic works, but bogs the server down for hours
select b.name, count(*)
from customers c
join branches b on b.orderappend = c.branchcode and b.enabled = 'T'
where c.deleted = 'N'
and c.link in (select first 80000 link from customers order by
weighted_Value desc)
group by 1
order by b.name
I almost thought this would work too, but its not valid sql
select first 80000 b.name, count(*)
from customers c
join branches b on b.orderappend = c.branchcode and b.enabled = 'T'
where c.deleted = 'N'
group by 1
order by c.weighted_value, b.name
any ideas on other more efficent ways to get this done would be greatly
appreciated.
TIA
Gary