MySQL Forums
Forum List  »  MySQL Query Browser

Re: How to write the following query ?
Posted by: Chad Bourque
Date: May 14, 2010 08:31AM

Amit,

Well then, you can do it this way:

select a.number - (x - 1)
  from blanks a
    join blanks b
      on a.number between b.number and b.number + x
  where a.Name = ''
    and b.Name = ''
  group by a.number
  having count(*) >= x;

This will return the following for various values of x:

x = 1 => 3, 4, 8, 9, 10, 11
x = 2 => 3, 8, 9, 10
x = 3 => 8, 9
x = 4 => 8

HTH,
Chad

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.