Results 1 to 2 of 2

Thread: MAX Occurences

  1. #1
    Join Date
    Jan 2010
    Posts
    3

    Unanswered: MAX Occurences

    Hi,

    I have the following table..

    StudentNo EmployeeNo RegistrationNo PracticalDate StartTime CourseCode
    S2201 E083 KPD392 2009-01-16 900 NULL
    S2814 E096 KPD234 2009-01-16 900 NULL
    S2809 E083 KPD339 2009-01-26 1200 NULL
    S2806 E083 MKA913 2009-01-26 1300 NULL
    S2808 E329 KPD234 2009-01-26 1300 NULL
    S2806 E177 KPF093 2009-01-26 1400 NULL
    S2806 E293 MPD330 2009-01-26 1400 NULL
    S2810 E083 KPF093 2009-01-27 1400 NULL
    S2812 E096 MKA913 2009-01-27 1500 NULL
    S2201 E177 MPD330 2009-01-27 1600 NULL
    S2812 E293 KPF093 2009-02-02 1000 NULL
    S2810 E177 KPD339 2009-02-02 1100 NULL
    S2807 E304 MMX980 2009-02-02 1200 NULL
    S2807 E293 KPD234 2009-02-02 1300 NULL
    S2808 E304 KPF093 2009-02-02 1300 NULL
    S2809 E329 MKA913 2009-02-02 1400 NULL
    S2810 E177 KPD339 2009-02-02 1400 NULL
    S2810 E177 KPD339 2009-02-02 900 NULL
    S2804 E293 KPD392 2009-02-09 1000 NULL
    S2452 E304 KPF093 2009-02-09 900 NULL
    S2201 E096 KPD339 2009-02-16 1000 NULL
    S2814 E083 KPD234 2009-02-16 1000 NULL
    S2804 E183 KPD392 2009-02-16 1400 NULL
    S2814 E183 MMX980 2009-02-16 1700 NULL
    S2201 E177 MPD330 2009-02-16 900 NULL

    How do I go about getting the 'EmployeeNo' who has thought the most number of sessions.
    E.g the MAX occurrences for E177.

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Several methods. The simplest (and proprietary) method that will work in any version of SQL Server:
    Code:
    SELECT TOP 1 EmployeeNo
    FROM [the following table]
    GROUP BY EmployeeNo
    ORDER BY COUNT(ALL EmployeeNo) DESC
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •