This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes tough logic question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Other » Programming Diversions
Reply Bookmark "tough logic question" Watch "tough logic question" New topic
Author

tough logic question

vishal gaiky
Greenhorn

Joined: Jun 06, 2012
Posts: 19
hello friends,
i have one database in that i have 100 questions..out or hudred i want to show any25 rows..and out of 25 row i want to show 1-5 number rows of database compulsary..how to achieve it
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 945
vishal gaiky wrote:hello friends,
i have one database in that i have 100 questions..out or hudred i want to show any25 rows..and out of 25 row i want to show 1-5 number rows of database compulsary..how to achieve it



I don't quite understand the question. Do you want to display 25 or 5 rows? And when you say "any25" do you mean you want to pick 25 random rows?

Since I know a clever (I like to think) way to show some number of random rows from a table in T-SQL / SQL Server, I'm going to pretend that that's what you're looking for:

Each time NEWID() is called, it returns a random 128 bit identifier. Each time the SELECT statement is run, a new temporary id is assigned to each row. Then the rows are sorted by this random number. Finally, the first 25 (or however many) rows are retrieved.

If you can clarify your question, we may be able to refine the solution.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9946
    
    6

I also don't see how this is a "logic" question, so much as an "SQL" question...


Never ascribe to malice that which can be adequately explained by stupidity.
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 945
fred rosenberger wrote:I also don't see how this is a "logic" question, so much as an "SQL" question...

I suppose we could get into a discussion on whether SQL is logical.
vishal gaiky
Greenhorn

Joined: Jun 06, 2012
Posts: 19
i want to display any 25 questions...5 questions per page..and total five pages.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9946
    
    6

Note that these two things are completely unrelated:

1) Getting a random 25 questions from a database
2) Assuming you have 25 questions, display them 5 per page.

I'd even make it more generic...given a list of some unknown size, display them X per page. that way, if you later decide you want 30 questions 3 per page, or 100 questions 10 per page, or 5 questions 1 per page, your method is still usable.

So...do you want help getting the random number of questions, or do you need help formatting/printing them X-per-page?
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 945
fred rosenberger wrote:Note that these two things are completely unrelated:

1) Getting a random 25 questions from a database
2) Assuming you have 25 questions, display them 5 per page.

I'd even make it more generic...given a list of some unknown size, display them X per page. that way, if you later decide you want 30 questions 3 per page, or 100 questions 10 per page, or 5 questions 1 per page, your method is still usable.

So...do you want help getting the random number of questions, or do you need help formatting/printing them X-per-page?


Given my development environment, I'd use a Java, C# or Perl program to issue the SQL command mentioned earlier to select Y (25) questions from the DB and then print them out X (5) per page with appropriate spacing, control characters, etc.

Would anyone use a pure SQL solution to pick the questions and generate the output? If so, how?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tough logic question
 
Similar Threads
display no results
how to show a row of data table in two rows?
overwriting methods
Alternate colors to table rows
JavaScript DataStructures