Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2003
    Posts
    126

    Question Unanswered: Combined into one select

    Hi all,

    I have the following:

    Code:
    select  count([Account Number]) AS UNDER25_12_SINGLE from OH_UNDER25_12MONTHS where AccountCount = 1
    select  count([Account Number]) AS UNDER25_12_MULTIPLE from OH_UNDER25_12MONTHS where AccountCount > 1
    select  count([Account Number]) AS UNDER25_36_SINGLE from OH_UNDER25_36MONTHS where AccountCount = 1
    select  count([Account Number]) AS UNDER25_36_MULTIPLE from OH_UNDER25_36MONTHS where AccountCount > 1
    select  count([Account Number]) AS UNDER25_60_SINGLE from OH_UNDER25_60MONTHS where AccountCount = 1
    select  count([Account Number]) AS UNDER25_60_MULTIPLE from OH_UNDER25_60MONTHS where AccountCount > 1
    Is there anyway to combined them into one query? So I get one result?

    Thanks,

    Ken

  2. #2
    Join Date
    Nov 2002
    Posts
    9

    Re: Combined into one select

    Place UNION between the select statements.

    Originally posted by GA_KEN
    Hi all,

    I have the following:

    Code:
    select  count([Account Number]) AS UNDER25_12_SINGLE from OH_UNDER25_12MONTHS where AccountCount = 1
    select  count([Account Number]) AS UNDER25_12_MULTIPLE from OH_UNDER25_12MONTHS where AccountCount > 1
    select  count([Account Number]) AS UNDER25_36_SINGLE from OH_UNDER25_36MONTHS where AccountCount = 1
    select  count([Account Number]) AS UNDER25_36_MULTIPLE from OH_UNDER25_36MONTHS where AccountCount > 1
    select  count([Account Number]) AS UNDER25_60_SINGLE from OH_UNDER25_60MONTHS where AccountCount = 1
    select  count([Account Number]) AS UNDER25_60_MULTIPLE from OH_UNDER25_60MONTHS where AccountCount > 1
    Is there anyway to combined them into one query? So I get one result?

    Thanks,

    Ken

  3. #3
    Join Date
    Jan 2003
    Posts
    126
    Union sort of worked, but I need the data in columns, union gave me rows.

  4. #4
    Join Date
    Feb 2003
    Location
    Germany
    Posts
    53
    try this

    select
    (select count([Account Number]) from OH_UNDER25_12MONTHS where AccountCount = 1) as UNDER25_12_SINGLE ,
    (select count([Account Number]) from OH_UNDER25_12MONTHS where AccountCount > 1) as UNDER25_12_MULTIPLE
    :
    :

  5. #5
    Join Date
    Nov 2002
    Posts
    9
    Try this:

    Code:
    select * from
    (select  count([Account Number]) AS UNDER25_12_SINGLE from OH_UNDER25_12MONTHS where AccountCount = 1) as A,
    (select  count([Account Number]) AS UNDER25_12_MULTIPLE from OH_UNDER25_12MONTHS where AccountCount > 1) as B,
    (select  count([Account Number]) AS UNDER25_36_SINGLE from OH_UNDER25_36MONTHS where AccountCount = 1) as C,
    (select  count([Account Number]) AS UNDER25_36_MULTIPLE from OH_UNDER25_36MONTHS where AccountCount > 1) as D,
    (select  count([Account Number]) AS UNDER25_60_SINGLE from OH_UNDER25_60MONTHS where AccountCount = 1) as E,
    (select  count([Account Number]) AS UNDER25_60_MULTIPLE from OH_UNDER25_60MONTHS where AccountCount > 1) as F
    Originally posted by GA_KEN
    Union sort of worked, but I need the data in columns, union gave me rows.

  6. #6
    Join Date
    Jan 2003
    Posts
    126
    Originally posted by msieben
    try this

    select
    (select count([Account Number]) from OH_UNDER25_12MONTHS where AccountCount = 1) as UNDER25_12_SINGLE ,
    (select count([Account Number]) from OH_UNDER25_12MONTHS where AccountCount > 1) as UNDER25_12_MULTIPLE
    :
    :

    This works just like I wanted! I knew there had to be a way! I've been pulling my hair out trying to get it to work!

  7. #7
    Join Date
    Jan 2003
    Posts
    126
    You guys are awesome!!

    Thanks for all your help!

    Ken

  8. #8
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249
    select
    (select count([Account Number]) from OH_UNDER25_12MONTHS where AccountCount = 1) AS UNDER25_12_SINGLE
    ,(select count([Account Number]) from OH_UNDER25_12MONTHS where AccountCount > 1) AS UNDER25_12_MULTIPLE
    ,(select count([Account Number]) from OH_UNDER25_36MONTHS where AccountCount = 1) AS UNDER25_36_SINGLE
    ,(select count([Account Number]) from OH_UNDER25_36MONTHS where AccountCount > 1) AS UNDER25_36_MULTIPLE
    ,(select count([Account Number]) from OH_UNDER25_60MONTHS where AccountCount = 1) AS UNDER25_60_SINGLE
    ,(select count([Account Number]) from OH_UNDER25_60MONTHS where AccountCount > 1) AS UNDER25_60_MULTIPLE

    Good luck !

Posting Permissions

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