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. file no frequency in sql 2008

file no frequency in sql 2008

Scheduled Pinned Locked Moved Database
databasequestion
5 Posts 3 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.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    i have a file_no field in my accounting_payment table and i want to run a query to see the frequency of every file, means how many times every file is listed in the table?

    M 1 Reply Last reply
    0
    • J Jassim Rahma

      i have a file_no field in my accounting_payment table and i want to run a query to see the frequency of every file, means how many times every file is listed in the table?

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      use the count() and group by operators

      Select count(*),file_no from accounting_payment group by file_no

      Never underestimate the power of human stupidity RAH

      J 1 Reply Last reply
      0
      • M Mycroft Holmes

        use the count() and group by operators

        Select count(*),file_no from accounting_payment group by file_no

        Never underestimate the power of human stupidity RAH

        J Offline
        J Offline
        Jassim Rahma
        wrote on last edited by
        #3

        But I also want to assign the Top number#? For example

        Select TOP 5 count(*), file_no from accounting_payment

        But to show the TOP (frequency) not the Top (position) Similarly I want to do it for the amount, for example:

        Select TOP 5 max(amount_paid), file_no from accounting_payment

        M P 2 Replies Last reply
        0
        • J Jassim Rahma

          But I also want to assign the Top number#? For example

          Select TOP 5 count(*), file_no from accounting_payment

          But to show the TOP (frequency) not the Top (position) Similarly I want to do it for the amount, for example:

          Select TOP 5 max(amount_paid), file_no from accounting_payment

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Do some research in BOL into rownumber() and partition. Using these and a sub select you can get the top N records grouped by yourcriteria and ranked according to your sort requirements.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • J Jassim Rahma

            But I also want to assign the Top number#? For example

            Select TOP 5 count(*), file_no from accounting_payment

            But to show the TOP (frequency) not the Top (position) Similarly I want to do it for the amount, for example:

            Select TOP 5 max(amount_paid), file_no from accounting_payment

            P Offline
            P Offline
            ps_prakash02
            wrote on last edited by
            #5

            May be you can do like this, SELECT TOP 5 FREQUENCY, FILE_NO FROM (SELECT COUNT(*) FREQUENCY, FILE_NO FROM ACCOUNTING_PAYMENT GROUP BY FILE_NO) A ORDER BY FREQUENCY DESC

            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