Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008
    Posts
    2

    Unanswered: Range of Values in Columns

    Hi,

    Actually what I want to do is to create a view which would help me categorize the following data,


    Emp_ID account_ID account_Balance
    1 1 500
    1 2 1000
    1 3 0
    1 4 10000
    2 1 900
    2 2 7000

    as,

    emp_ID Accounts<=1000 (Accounts > 1000 and Accounts < 10000)
    1 3 1
    2 1 1


    Though, I know the sub-query solution for it but I want to prepare the view in a single query sort. Like we can do the group by on the account balance ranges.

    The problem with the group by thing is it gives data in the form,

    emp_ID Range Accounts
    1 <=1000 3
    1 >1000 and <10000 1
    2 <=1000 1
    2 >1000 and <10000 1

    Hope, I’ve made my point clear and your help would be precious for me.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT Emp_ID 
         , SUM(CASE WHEN account_Balance <= 1000
                    THEN 1 ELSE 0 END) AS Accounts_below_1000 
         , SUM(CASE WHEN account_Balance <= 10000
                    THEN 1 ELSE 0 END) AS Accounts_below_10000
      FROM daTable
    GROUP
        BY Emp_ID
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Aug 2008
    Posts
    2

    Thanx Dear

    O Dear, It worked like a charm.

    Thanks Very Much and it would be my pleasure if I could be any help to you as well.

Posting Permissions

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