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 951273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:42:32+00:00 2026-05-15T23:42:32+00:00

below is a sql server table, which is used to hold users prediction for

  • 0

below is a sql server table, which is used to hold users prediction for soccer matches. a user can predict either a home win, an away win or a draw/tie for a specific soccer match.

how can i query this table to find the top 3 predictions, the top 3 games must be distinct gameId’s

either SQL or LINQ solution would be much appriciated

alt text http://preview.robson-brown.com/capture.png

  • 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. Editorial Team
    Editorial Team
    2026-05-15T23:42:33+00:00Added an answer on May 15, 2026 at 11:42 pm

    I’ll assume you want the strongest predictions, i.e., the games where the most people agree on the outcome.

     var predictions = db.Predictions
                         .GroupBy( g => g.gameId )
                         .Select( g => new 
                          {
                                gameId = g.Key,
                                homeWin = g.Sum( h => h.homeWin ),
                                awayWin = g.Sum( a => a.awayWin ),
                                draw = g.Sum( d => d.draw )
                          })
                         .Select( g => new 
                          {
                                gameId = g.gameId,
                                prediction = g.homeWin > g.awayWin 
                                                 ? (g.homeWin > draw 
                                                        ? 'homeWin'
                                                        : 'draw')
                                                 : (g.awayWin > g.draw
                                                        ? 'awayWin'
                                                        : 'draw'),
                                strength = g.homeWin > g.awayWin 
                                                 ? (g.homeWin > draw 
                                                        ? g.homeWin
                                                        : g.draw) 
                                                 : (g.awayWin > g.draw 
                                                        ? g.awayWin 
                                                        : g.draw)
                          })
                         .OrderByDescending( g => g.strength )
                         .Take(3);
    

    You might be able to combine the two selects, but IMO it would hurt the readability of the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have four tables like below in sql server 2008 : TABLE 1 ->
I have a table similar to below in sql server 2005 date_column | field1
I have a Money column in my SQL Server 2008 table. In my below
Is there any difference between the below 2 CREATE TABLE statements in SQL Server
I'm using Sql-Server, and I have the below query which returns all columns that
I have a table in sql server 2005 which holds an ip range and
I'm using SQL Server 2K8 and have a table used solely to generate ids
I have a table in SQL Server in which one of the columns is
I have a positions table in SQL Server 2008R2 (definition below). In the system
QI want to display queried records from SQl Server which are in a table

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.