pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Need help with a college SQL exam question...
4+ messages / 4 participants
[nested] [flat]

* Need help with a college SQL exam question...
@ 2001-11-29 15:54 dejauser2001@yahoo.co.uk <dejauser2001@yahoo.co.uk>
  2001-12-03 19:13 ` Re: Need help with a college SQL exam question... Josh Berkus <josh@agliodbs.com>
  2001-12-04 08:54 ` Re: Need help with a college SQL exam question... Arian Prins <prinsarian@zonnet.nl>
  0 siblings, 2 replies; 4+ messages in thread

From: dejauser2001@yahoo.co.uk @ 2001-11-29 15:54 UTC (permalink / raw)
  To: pgsql-sql

Hi everyone,

Its coming close to my January examinations, and
while revising I got stuck in the follwing question.
I literally spent hours trying to solve it but I
just can't :(

Consider the folowing relations; (where the * means
primary key)

The "Car Rental" database
-------------------------

customer(*cust_num*,cust_name)
hire(*car_reg*,*cust_num*,*hire_date*)
shop(*outlet_code*,address)
car_model(*model*,make,num_seats,max_speed)
car(*car reg*,model,year, outlet_code)

And the question is;
Using SQL (using SELECT, FROM, WHERE, GROUP BY, COUNT(*), etc..) write a query
to list the names of customers who have borrowed cars made by every maker.

Thats it! Hard or what?

Any help greatly apreciated



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Need help with a college SQL exam question...
  2001-11-29 15:54 Need help with a college SQL exam question... dejauser2001@yahoo.co.uk <dejauser2001@yahoo.co.uk>
@ 2001-12-03 19:13 ` Josh Berkus <josh@agliodbs.com>
  2001-12-04 14:47   ` Re: Need help with a college SQL exam question... Roland Roberts <roland@astrofoto.org>
  1 sibling, 1 reply; 4+ messages in thread

From: Josh Berkus @ 2001-12-03 19:13 UTC (permalink / raw)
  To: dejauser2001@yahoo.co.uk; pgsql-sql

"dejauser":

> Its coming close to my January examinations, and
> while revising I got stuck in the follwing question.
> I literally spent hours trying to solve it but I
> just can't :(

hmmm ... I don't think it's according to the honor code to ask us to
help with your exams.  ;-)

> And the question is;
> Using SQL (using SELECT, FROM, WHERE, GROUP BY, COUNT(*), etc..)
> write a query
> to list the names of customers who have borrowed cars made by every
> maker.

It's doable.  Just think "nested subselects" and heavy use of the HAVING
clause.  They're also screwing with you by providing an irrelevant table
(shop) and not providing a relevant table (makers).  If I was the
professor, I'd give the question writer a D+ for database design ...

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Need help with a college SQL exam question...
  2001-11-29 15:54 Need help with a college SQL exam question... dejauser2001@yahoo.co.uk <dejauser2001@yahoo.co.uk>
  2001-12-03 19:13 ` Re: Need help with a college SQL exam question... Josh Berkus <josh@agliodbs.com>
@ 2001-12-04 14:47   ` Roland Roberts <roland@astrofoto.org>
  0 siblings, 0 replies; 4+ messages in thread

From: Roland Roberts @ 2001-12-04 14:47 UTC (permalink / raw)
  To: pgsql-sql

>>>>> "Josh" == Josh Berkus <josh@agliodbs.com> writes:

    Josh> It's  doable.  Just think "nested subselects"  and heavy use
    Josh> of  the HAVING  clause.  They're also  screwing with  you by
    Josh>  providing an irrelevant  table (shop)  and not  providing a
    Josh> relevant table (makers).  If I was the professor, I'd give
    Josh> the question writer a D+ for database design ...

I would treat the table car_model as providing a complete list of
makes as well, i.e., "select distinct make from car_model" provides a
list of all car makes (from which the customer can borrow).

I'd agree that the database *should* have a makers table to constrain
the values of that column.  A real-life database without it is prone
to *lots* of data entry errors (let's see, should I put in GM, Chevy
or Chevrolet?).

roland
-- 
		       PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD                             RL Enterprises
roland@rlenter.com                     76-15 113th Street, Apt 3B
roland@astrofoto.org                       Forest Hills, NY 11375



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Need help with a college SQL exam question...
  2001-11-29 15:54 Need help with a college SQL exam question... dejauser2001@yahoo.co.uk <dejauser2001@yahoo.co.uk>
@ 2001-12-04 08:54 ` Arian Prins <prinsarian@zonnet.nl>
  1 sibling, 0 replies; 4+ messages in thread

From: Arian Prins @ 2001-12-04 08:54 UTC (permalink / raw)
  To: pgsql-sql

Hi,

Nice question.... I made a nice query that'll get you the result. I will not give
you the code because: 1. it's your exam, 2. I think It has some "rough edges" and
I don't want you to get the blame of my "edges" :-)

I'll give you a narrative version:

1. I'm counting the number of distinct makes...
2. I'm counting the number of distinct makes every customer has ever used (join,
join, join!) and compare that number to the result of #1

This of course happens in subqueries. I do not use HAVINGs though...
And on the design of the exam-database; lousy.

Succes,
A. Prins.

"dejauser2001@yahoo.co.uk" schreef:

> Hi everyone,
>
> Its coming close to my January examinations, and
> while revising I got stuck in the follwing question.
> I literally spent hours trying to solve it but I
> just can't :(
>
> Consider the folowing relations; (where the * means
> primary key)
>
> The "Car Rental" database
> -------------------------
>
> customer(*cust_num*,cust_name)
> hire(*car_reg*,*cust_num*,*hire_date*)
> shop(*outlet_code*,address)
> car_model(*model*,make,num_seats,max_speed)
> car(*car reg*,model,year, outlet_code)
>
> And the question is;
> Using SQL (using SELECT, FROM, WHERE, GROUP BY, COUNT(*), etc..) write a query
> to list the names of customers who have borrowed cars made by every maker.
>
> Thats it! Hard or what?
>
> Any help greatly apreciated




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2001-12-04 14:47 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-11-29 15:54 Need help with a college SQL exam question... dejauser2001@yahoo.co.uk <dejauser2001@yahoo.co.uk>
2001-12-03 19:13 ` Josh Berkus <josh@agliodbs.com>
2001-12-04 14:47   ` Roland Roberts <roland@astrofoto.org>
2001-12-04 08:54 ` Arian Prins <prinsarian@zonnet.nl>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox