Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

SQL problem - for JDBC cowboys

 
Ranch Hand
Posts: 47
  • 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
  • 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 ]
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic