Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > Ntile with MySql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-28-08, 07:06
silas silas is offline
Registered User
 
Join Date: Mar 2007
Posts: 97
Ntile with MySql

Hello,

is there a way to do Ntile with MySql? Maybe with stored Procedure or something else?

If not, do you have an idea, how to simulate on Client-Side, using c# and ado?

Thank you
Reply With Quote
  #2 (permalink)  
Old 05-28-08, 07:26
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,539
yes, a stored procedure can do anything
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 05-28-08, 07:51
silas silas is offline
Registered User
 
Join Date: Mar 2007
Posts: 97
Oh, that takes a load of my mind.

I currently use the following expression in Sql Server

Select year, quarter, price, ntile(3) over (partition by year, quarter order by price)

to retrieve something like ABC Price-Ranges for each quarter.

I don't know how much work it is, to simulate this in a stored procedure for MySql. Unfortunately I can't find any sample code on the Internet. This doesn't make me very confident.

How many lines of Code will such a procedure have, about 10, 50 or maybe 100?

Do you know any sample Code or can give me hint where to look at?
Reply With Quote
  #4 (permalink)  
Old 05-28-08, 08:00
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,539
oh, i'd say it would have maybe somewhere between 9 and 37 lines of code, give or take

the stored proc would run this query:
Code:
SELECT year, quarter, price FROM daTable ORDER BY year, quarter, price
and then process the rows in sequence
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #5 (permalink)  
Old 05-28-08, 08:10
silas silas is offline
Registered User
 
Join Date: Mar 2007
Posts: 97
And what about Sql-Function, is it possible to create such a Sql-Function, so I can use it in the select statement? Just like ntile for Sql Server.
Reply With Quote
  #6 (permalink)  
Old 05-28-08, 09:27
silas silas is offline
Registered User
 
Join Date: Mar 2007
Posts: 97
Not possible?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On