Results 1 to 3 of 3

Thread: Simple Query!

  1. #1
    Join Date
    Jul 2002
    Posts
    8

    Unanswered: Simple Query!

    Hello all,

    I want to query a single column in recordset whose values should be halfway divided. Eg. if there are 4 names A, B, C and D res in a table. I want a recordset where column1 will have values A and B and in column2 will have values C and D.

    Regards,
    MaheshB

  2. #2
    Join Date
    Oct 2001
    Location
    England
    Posts
    426
    select name1, name2
    from
    (
    select name1 = name, name2 = (select min(t2.name) from tbl t2 where t2.name > t.name) ,
    rownum = (select count(*) from tbl t2 where t2.name <= t.name)
    from tbl t) as a
    where rownum%2 = 1

  3. #3
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249
    select Column1=min(x1.name),Column2=max(x1.name)
    from
    (
    select t1.name,Cnt=count('x')
    from tbl t1
    join tbl t2 on t1.name>=t2.name
    group by t1.name
    ) x1
    cross join (select HalfCnt=count(*)/2 from tbl) xx
    group by (x1.Cnt+xx.HalfCnt)%xx.HalfCnt
    order by Column1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •