wood burning stoves*
The moose likes Programming Diversions and the fly likes SQL problem - for JDBC cowboys 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 "SQL problem - for JDBC cowboys" Watch "SQL problem - for JDBC cowboys" New topic
Author

SQL problem - for JDBC cowboys

Pavel Cherkashin
Ranch Hand

Joined: Mar 04, 2005
Posts: 47
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 - <br />SCJP, SCWCD, SCDJWS, SCBCD, SCEA, ...<br />www.linkedin.com/in/pcherkas
Pavel Cherkashin
Ranch Hand

Joined: Mar 04, 2005
Posts: 47
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
 
subject: SQL problem - for JDBC cowboys