Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Posts
    5

    Unanswered: db2 database query problem

    Hi,
    we r facing problem in DB2 database.


    I need something like:
    SELECT
    Count([Field1] WHERE [Field1=1],count[Field1] WHERE [Field1=2],[Feild3] WHERE ..................

    example:we cannot seem to make a query that will give me a count for each field, but only counting the yes or no options.

    Help please?

    Thanks everyone!
    subhash

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: db2 database query problem

    See if this helps

    select * from department

    DEPTNO DEPTNAME MGRNO ADMRDEPT LOCATION
    ------ ----------------------------- ------ -------- ----------------
    A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00 -
    B01 PLANNING 000020 A00 -
    C01 INFORMATION CENTER 000030 A00 -
    D01 DEVELOPMENT CENTER - A00 -
    D11 MANUFACTURING SYSTEMS 000060 D01 -
    D21 ADMINISTRATION SYSTEMS 000070 D01 -
    E01 SUPPORT SERVICES 000050 A00 -
    E11 OPERATIONS 000090 E01 -
    E21 SOFTWARE SUPPORT 000100 E01 -

    9 record(s) selected.


    select count(case when deptno='A00' then deptno end) as A00, count(case when deptno='B01' then deptno end) as B01 , count(case when deptno like 'E%' then deptno end) as E from department

    A00 B01 E
    ----------- ----------- -----------
    1 1 3

    1 record(s) selected.


    0


    Originally posted by subhash13
    Hi,
    we r facing problem in DB2 database.


    I need something like:
    SELECT
    Count([Field1] WHERE [Field1=1],count[Field1] WHERE [Field1=2],[Feild3] WHERE ..................

    example:we cannot seem to make a query that will give me a count for each field, but only counting the yes or no options.

    Help please?

    Thanks everyone!
    subhash
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Aug 2003
    Posts
    5

    Re: db2 database query problem

    Thank you very much Sathyaram. Our problem is solved.

    Originally posted by sathyaram_s
    See if this helps

    select * from department

    DEPTNO DEPTNAME MGRNO ADMRDEPT LOCATION
    ------ ----------------------------- ------ -------- ----------------
    A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00 -
    B01 PLANNING 000020 A00 -
    C01 INFORMATION CENTER 000030 A00 -
    D01 DEVELOPMENT CENTER - A00 -
    D11 MANUFACTURING SYSTEMS 000060 D01 -
    D21 ADMINISTRATION SYSTEMS 000070 D01 -
    E01 SUPPORT SERVICES 000050 A00 -
    E11 OPERATIONS 000090 E01 -
    E21 SOFTWARE SUPPORT 000100 E01 -

    9 record(s) selected.


    select count(case when deptno='A00' then deptno end) as A00, count(case when deptno='B01' then deptno end) as B01 , count(case when deptno like 'E%' then deptno end) as E from department

    A00 B01 E
    ----------- ----------- -----------
    1 1 3

    1 record(s) selected.


    0

Posting Permissions

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