1. We have moved to a new forum! There may be a few things not working properly so please let us know if you find a bug. Remember to use the bbCode [ sql ] tag for SQL statements.

Show Distinct Values Along With Count

Discussion in 'SQL - Questions and Answers' started by schepsr, May 12, 2008.

  1. schepsr New Member

    I have a table where there is a character field of 60 bytes with invalid data in the last four bytes of the field.
    I want to see what is in these last four bytes along with a count of how many rows in the table contain them.

    This query shows me what distinct values are contained in the last four bytes:
    SQL:
    SELECT DISTINCT(SUBSTRING(CUSTOM_DATA,56,4))
    FROM ....


    And this gives me the count of how many different distinct values there are:
    SQL:
    SELECT COUNT(DISTINCT(SUBSTRING(CUSTOM_DATA,56,4)))
    FROM ...


    What do I need to add to the first select statement to not only show what's in the last four bytes of the field, but to also tell me how many rows in the table contains them?
  2. Dimitar Guest

    Hi,

    Try GROUP BY.
    Do you need help with the query?

    Dimitar
  3. Unregistered Guest

    Reply:You may modify your select statement as-:
    SQL:
    SELECT COUNT(*)  FROM.....WHERE CUSTOM_DATA LIKE '%(SUBSTRING(CUSTOM_DATA,56,4))'

Share This Page