Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Need Query for this

Need Query for this

Scheduled Pinned Locked Moved Database
databasesql-serversysadminregexlounge
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sujithkumarsl
    wrote on last edited by
    #1

    I am using sql server 2005. I have a table like this

    COL1 COL2
    A 1
    A 1
    B 2
    C 1
    C 2

    and i need output like this

    COL1 COL2 No:
    A 1 2
    B 2 1
    C 1 1
    C 2 1

    How many times the same COL1 and COL2 coming, that should be the column NO: in the output.. Please not that here i dont have any inputs like A,1 etc.... This is just the pattern, so i need a general quesry.

    My small attempt...

    _ S 2 Replies Last reply
    0
    • S sujithkumarsl

      I am using sql server 2005. I have a table like this

      COL1 COL2
      A 1
      A 1
      B 2
      C 1
      C 2

      and i need output like this

      COL1 COL2 No:
      A 1 2
      B 2 1
      C 1 1
      C 2 1

      How many times the same COL1 and COL2 coming, that should be the column NO: in the output.. Please not that here i dont have any inputs like A,1 etc.... This is just the pattern, so i need a general quesry.

      My small attempt...

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      What you need is a very simple select statement using grouping.

      select Col1, Col2, count(col1) as No
      from tablename
      group by Col1, Col2
      order by Col1, Col2

      Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010

      S 1 Reply Last reply
      0
      • S sujithkumarsl

        I am using sql server 2005. I have a table like this

        COL1 COL2
        A 1
        A 1
        B 2
        C 1
        C 2

        and i need output like this

        COL1 COL2 No:
        A 1 2
        B 2 1
        C 1 1
        C 2 1

        How many times the same COL1 and COL2 coming, that should be the column NO: in the output.. Please not that here i dont have any inputs like A,1 etc.... This is just the pattern, so i need a general quesry.

        My small attempt...

        S Offline
        S Offline
        sujithkumarsl
        wrote on last edited by
        #3

        hi all...... i got the solution... i think we can use the same technique which use for duplicate checking

        SELECT COL1, COL2, count(*)
        FROM table
        GROUP BY COL1, COL2

        i think this is fine

        My small attempt...

        _ 1 Reply Last reply
        0
        • S sujithkumarsl

          hi all...... i got the solution... i think we can use the same technique which use for duplicate checking

          SELECT COL1, COL2, count(*)
          FROM table
          GROUP BY COL1, COL2

          i think this is fine

          My small attempt...

          _ Offline
          _ Offline
          _Damian S_
          wrote on last edited by
          #4

          Wow, looks remarkably like the answer I gave you 6 mins ago... ;-)

          Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010

          S 1 Reply Last reply
          0
          • _ _Damian S_

            What you need is a very simple select statement using grouping.

            select Col1, Col2, count(col1) as No
            from tablename
            group by Col1, Col2
            order by Col1, Col2

            Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010

            S Offline
            S Offline
            sujithkumarsl
            wrote on last edited by
            #5

            you are great

            My small attempt...

            1 Reply Last reply
            0
            • _ _Damian S_

              Wow, looks remarkably like the answer I gave you 6 mins ago... ;-)

              Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010

              S Offline
              S Offline
              sujithkumarsl
              wrote on last edited by
              #6

              i seen your comment after i post my... anyway thanks... :-D

              My small attempt...

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups