hopefully an easy one

I need to determine the top 20 most frequent occurences of a value in a specific field using SQL.



Answer this question

hopefully an easy one

  • sks04

    you mean something like this

    use northwind
    select top 20 customerid, count(customerid) as ordercount from orders
    group by customerid
    order by ordercount desc



  • DanUp

    This query is from SQL 2005;

    select top 20 c.system_type_id

    from sys.all_columns c

    inner join sys.systypes st

    on c.system_type_id = st.xtype

    group by system_type_id

     

    or something like this

    select top 20 st.[name]

    from sys.all_columns c

    inner join sys.systypes st

    on c.system_type_id = st.xtype

    group by st.[name]



  • Itzik Paz

    Thank you very much for your response.


  • hopefully an easy one