Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kiran83
    New Member
    • Feb 2008
    • 18

    #1

    Help

    for ex one table is there like charge ,fields are chargeid,charge name

    chargeid's are having duplicates like chargeid
    101
    101
    102
    .......
    1.I want to disply the colmns of chargeid's and no.of times like(in desc order)

    chargeid no. of times
    101 2
    102 ----

    2.I want to display only those chargeid's are maximum times repeated
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by kiran83
    for ex one table is there like charge ,fields are chargeid,charge name

    chargeid's are having duplicates like chargeid
    101
    101
    102
    .......
    1.I want to disply the colmns of chargeid's and no.of times like(in desc order)

    chargeid no. of times
    101 2
    102 ----

    2.I want to display only those chargeid's are maximum times repeated
    Could you please post what you have tried so far??

    Comment

    • kiran83
      New Member
      • Feb 2008
      • 18

      #3
      Originally posted by amitpatel66
      Could you please post what you have tried so far??
      select chargeid,count( *) from charges group by chargeid having count(*)>1 order by 2

      this query displays chargeid's and corresponding number of times for the chargeid now i want to disply only maximum number of chargeid's list in this table (suppose 101 chargeid is maximum used in the table)

      like

      chargeid no. of times
      101 1
      101 2

      (or)

      chargename chargeid

      101
      101

      Comment

      • deepuv04
        Recognized Expert New Member
        • Nov 2007
        • 227

        #4
        Originally posted by kiran83
        select chargeid,count( *) from charges group by chargeid having count(*)>1 order by 2

        this query displays chargeid's and corresponding number of times for the chargeid now i want to disply only maximum number of chargeid's list in this table (suppose 101 chargeid is maximum used in the table)

        like

        chargeid no. of times
        101 1
        101 2

        (or)

        chargename chargeid

        101
        101

        hi,
        if you want to get only the maximum number of times repeated chargid then
        use the following query

        thanks

        select top 1 chargeid,count( *) from charges group by chargeid having count(*)>1 order by 2 desc

        Comment

        • kiran83
          New Member
          • Feb 2008
          • 18

          #5
          now i want to disply only the maximum no. of chargeid's list(individual list) like below ex:


          ex:

          chargeid chargename
          101 ------- xxx
          101 ------- yyy
          101 -------- aaa
          101 ------- kkk

          Comment

          • deepuv04
            Recognized Expert New Member
            • Nov 2007
            • 227

            #6
            Originally posted by kiran83
            now i want to disply only the maximum no. of chargeid's list(individual list) like below ex:


            ex:

            chargeid chargename
            101 ------- xxx
            101 ------- yyy
            101 -------- aaa
            101 ------- kkk

            SELECT charges.chargei d ,charges.charge name from charges INNER JOIN
            ( select top 1 chargeid,count( *) from charges group by chargeid having count(*)>1 order by 2 ) AS C1
            on charges.chargId = c1.chargid

            Comment

            Working...