Search:
www.rocket99.com : Technical Guides Sybase Oracle UNIX Javascript


Technical Guides
Sybase
Oracle
UNIX
Javascript




After Work

Highlife Adventures
The best club in Chicago
for Chicago Singles is Highlife Adventures!


Jersey Girl Shirts
Are you looking for a
Jersey Girl T-Shirt ?



Kyoto Sushi
in Chicago, on Lincoln Ave.
Moody's Pub
in Chicago, has great burgers
Skylark
in Chicago, on Halsted .. excellent Friday fish fry!


Sybase » T-SQL » Analytic » NTile

N-Tile Analytic Queries

     



Analytic Functions: N-Tile



N-tile type queries allow you to ask for results based on which ranking group they fall into.



For example (5 parts, quintile):
"Show me all records where they fall in the top fifth of the set, ranked by gross sales."



There is no n-tile function in ASE (there is in IQ) ... here is how to do set up the query using
Transact-SQL.




create table #rank99 (
rec_id numeric(8) identity,
salesman_id integer not null,
gross_sales_amt real not null
)
go

declare @piece real

insert into #rank99 ( gross_sales_amt, salesman_id )
select gross_sales_amt, salesman_id
from regional_sales
where year_month_id = 200510
and isnull(gross_sales_amt,0) > 0
order by 1

select @piece = @@rowcount/5.0

select ceiling(rec_id/@piece) 'Quin-Tile', salesman_id, gross_sales_amt
from #rank99
order by 1,2,3
go










Sybase : Related Topics


Sybase Web Site
Sybase Mobile Web Site
Oracle Web Site





Site Index About this Guide to Sybase, Oracle, and UNIX Contact Us Advertise on this site




Copyright © 2008 Citisoft Inc All Rights Reserved.