• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL problem - for JDBC cowboys

 
Pavel Cherkashin
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a matter of fact the problem does not have any relation to JDBC, rather the classical SQL.
You have SQL table "table" containing two columns: "name" and
"gadget".
Both columns contain text strings:




Some specific name is given as the input.
Please write SQL statement(s) which get the input returns list of names
of the persons having set of unique gadgets equal or greater to the
person which name was given as the input.


Examples:

input: oleg
output: anton
Oleg has (computer, keyboard, mouse).
Anton has more gadgets (computer, keyboard, mouse) + TV.

input: seva
output: alex
Seva has (phone, computer).
Alex has (phone, computer) + TV + mouse.
Oleg, Anton aren't printed, since both haven't phone.

input: alex
output: <EMPTY>
[ February 22, 2008: Message edited by: Pavel Cherkashin ]
 
Pavel Cherkashin
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one answer is published by me (maybe not the most efficient)

the query uses given parameter value "alex".

First i wrote the query, which selects all gadgets of given person name.
Then the query, returning all gadgets, grouped by name.
Then the query, which selects all names and their gadgets the given person("alex") has, but the selected person has not.

And at last count missing gadgets and if the number is 0 (no gadgets, the given person, the selected person has not), then this is a criteria for last result of name list.

Propose your queries, approaches, interesting to know.
[ February 22, 2008: Message edited by: Pavel Cherkashin ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic