ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Count function in SQL400

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Count function in SQL400

    Hello All,

    I have a file FILEA with the fileds A,B,C. I need the count for the each field in single SQL statement. Is it possible to get it ?
    Report should be as follows

    A B C

    Count(A) Count(B) Count(C)

  • #2
    Re: Count function in SQL400

    I am not sure you are correctly explaining your requirement. If you count fields A B and C in a file you would get the same value for each.
    the smoking gnu

    Comment


    • #3
      Re: Count function in SQL400

      Well.... You can... but it wont give you the right answer.

      Code:
      select count(field1) as field1,count(field1) as field2
      from mylib.myfile
      returns this

      Code:
             FIELD1          FIELD2 
          2,377,246       2,377,246
      It's just a count of how many records are there(except where the field is null). On IBM i(and the like) null fields haven't been super popular like on other machines.
      Last edited by danlong005; October 16, 2014, 06:15 AM. Reason: left out some words

      Comment


      • #4
        Re: Count function in SQL400

        Hi,

        Thank you very much for your replies ... Sorry for missing the clarity in the question.

        Yes I need the query when there are null values in the file.

        Thanks in advance ...!!!

        Comment


        • #5
          Re: Count function in SQL400

          In this way Count(A), Count(B), Count(C) and Count(*) may return different results.
          Count on a column will only count the NOT NULL values within the column. COUNT(*) will count all rows even though there would be a record that consists only of NULL values.
          You may have NULL values in a column if COUNT(colunm) and count(*) return different values

          Birgitta

          Comment


          • #6
            Re: Count function in SQL400

            It would help if you put a set of example rows together with values for fields A, B and C. Then you could show us the result you expect for the three counts. If we have samples and expected results, it's much easier to know what is needed.
            Tom

            There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

            Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

            Comment

            Working...
            X