aspose file tools*
The moose likes Programming Diversions and the fly likes tough logic question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Other » Programming Diversions
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: 1010
    
    3
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: 11411
    
  16

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


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1010
    
    3
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: 11411
    
  16

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: 1010
    
    3
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