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

  • SEARCH
  • Home
  • 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 8433815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:29:28+00:00 2026-06-10T06:29:28+00:00

I do not have a smart or at least working idea how to solve

  • 0

I do not have a smart or at least working idea how to solve following challenge:

I have 198 assignments and let each assignment solved by 10 persons, then I wrote everything in a PostgreSQL database by using Java hibernate & persistence API. That worked fine so far.

Sometimes I do have 10 different/distinct answers for an assignment – for other assignments I do have only 2 or 3 different/distinct answers (e.g. for the assignment “what is 5 + 5”, 8 persons told “10” and 2 persons told “25”)

Now I run a SQL statement to get a list with my assignments and the distinct answers:

 SELECT DISTINCT question, answer FROM survey INNER JOIN results ON results.survey_id=results.id;

what I get now is a result list that looks more or less like this:

+---------+----------+--------+
| ID      | Question | Answer | 
+---------+----------+--------+
| 1       | Q1      | 20      |
| 2       | Q1      | 22      | 
| 3       | Q1      | 25      | 
| 4       | Q1      | 21      | 
| 5       | Q1      | 22      | 
| 6       | Q1      | 10      | 
| 7       | Q1      | 20.5    |
| 8       | Q1      | 22.3    |
| 9       | Q1      | 28      |
| 10      | Q1      | 26      |
| 11      | Q2      | 52      |
| 12      | Q2      | 51      |
| 13      | Q3      | 78      |
| 14      | Q3      | 80      |
| ...     | ...     | ...     |
| ...     | ...     | ...     |
| ...     | ...     | ...     |
+---------+---------+---------+

now the challening part:

I want now randomly pick out 4 distinct answers (if possible) from each assignment (Q1, Q2, Q3, …) and create a new assignment where people have to vote on the best answer.

But as shown, sometimes I do have less then 4 distinct answers for an assignment. In this case I want to take everything that’s available.

How could I iterate through my list and perform this kind of “picking”?

P.S. it’s not very important to pick the answers randomly – would also be okay to pick the first 4 answers.

appreciate your help

regards

  • 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-06-10T06:29:29+00:00Added an answer on June 10, 2026 at 6:29 am

    if the resultset is that small i would just

    // if random is needed [see here][1] to adapt the criteria
    var answers = session.createCriteria(Answer.class)
        .setFetchMode("Question", FetchMode.eager)
        .list<Answer>();
    
    
    // map of orginal question to voting question
    Map<Question, Question> questions = new Hashmap<Question, Question>();
    for (Answer answer : answers)
    {
        if (questions.ContainsKey(answer.getQuestion()))
        {
            Question votingQuestion = questions.get(answer.getQuestion());
            if (votingQuestion.getPossibleAnswers().Count() < 4)
                votingQuestion.getPossibleAnswers().add(answer.Text);
        }
        else
        {
            Question votingQuestion = createVotingQuestion(answer.getQuestion());
            votingQuestion.getPossibleAnswers().add(answer.Text);
            questions.add(answer.getQuestion(), votingQuestion);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When it comes to web development I have always tried to work SMART not
I have the following task: Later this month, I will launch an Android smart
I can always start to write my own, but i'd rather not have to
First, I'll start off by saying that I do not have control over the
I'll start by saying that I have searched SO and not found an answer
Is it possible to start an array at an index not zero...I.E. you have
How can I use Process.Start(), but have the launched process not in the same
Did not have luck with these examples: Javascript File remove Javascript FSO DeleteFile Method
I have a Xaml file that does not have any code behind. I would
I have a website that does not have page refreshes when the visitor navigates

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.