sql statement problem

  • We have this database that records virus infections in our network. I have some trouble making a sql statement that queries what are the  viruses found and the number of times it is recorded and to display the top ten and i am a beginner in sql.

    Ex.

    Virusfound

    Codered

    codered

    nimda

    bugbear

    bugbear

    bugbear

    Swen

    Swen

    Swen

    Swen

    ..the result should be something like this..

    Virus  Count

    Swen 4

    Bugbear 3

    codered 2

    nimda 1

    Thanks.....

  • Without having your actual table structure this pseudocode

    select virusname, count(*) as no_of_recordings from yourtable group by virusname order by no_of_recordings desc

    should work

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • In Frank's solution, add TOP 10 after the SELECT.

    SELECT TOP 10 virusname..........

    -SQLBill

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply