Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 183073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:03:05+00:00 2026-05-11T15:03:05+00:00

I have a table with 3 fields like this: ProfessorID StudentID Mark P1 S1

  • 0

I have a table with 3 fields like this:

ProfessorID    StudentID    Mark P1             S1              9 P1             S2              8 P1             S3             10 P2             S1              7 P2             S2              2 P2             S3              4 P3             S4              5 P4             S1              6 

A professor can teach many students, and vice versa, a student can learn from many professor. When a student learns from a professor, he gets his mark.

My problem is showing list of professors who teach at least 2 students, and 2 students who get best marks from those professors. In example, the query result of this table is:

ProfessorID    StudentID    Mark P1             S1              9 P1             S3             10 P2             S1              7 P2             S3              4 

I’ve tried some solutions but they don’t work right.

How can I do this correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:03:06+00:00Added an answer on May 11, 2026 at 3:03 pm
    declare  @table table (ProfessorID nvarchar(2), StudentID nvarchar(2),Mark int)  insert into @table select 'P1', 'S1', 9 union all select 'P1', 'S2', 8 union all select 'P1', 'S3', 10 union all select 'P2', 'S1', 7 union all select 'P2', 'S2', 2 union all select 'P2', 'S3', 4 union all select 'P3', 'S4', 5 union all select 'P4', 'S1', 6  select * from @table o where o.StudentID IN (select top 2 s.StudentID from @table s where s.ProfessorId = o.ProfessorId order by Mark DESC) and o.ProfessorID IN (select p.ProfessorID from @table p group by p.ProfessorID having count(*) >= 2)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my Table structure like this :: ATT_Table : Fields - Act_ID, Assigned_To_ID,
I have a table like this, with three fields: User | Question# | Answer
I have a favorite table containing some fields like login_id,driver_id(One login_id may have many
I have user table having fields gender and first name like this.. The value
I have a table with several account fields like this: MAIN_ACCT GROUP_ACCT SUB_ACCT I
I have a table like this : YEAR int, Fields XML My XML column
We have a table with several fields, like 300+. the structure is like this:
I have a table like this: Sequence ID Date other fields 1 23 2012-01-01
I have a table like this : +-------+------------+------+-----+---------+-------+ | Field | Type | Null
I have a select like this: SELECT field1, field2, field3 FROM table WHERE field1=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.