Received: from hotmail.com (f113.pav2.hotmail.com [64.4.37.113]) by postgresql.org (8.11.3/8.11.4) with ESMTP id fBA8gvm64242; Mon, 10 Dec 2001 03:42:57 -0500 (EST) (envelope-from rickardo2010@hotmail.com) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 10 Dec 2001 00:42:58 -0800 Received: from 212.1.144.209 by pv2fd.pav2.hotmail.msn.com with HTTP; Mon, 10 Dec 2001 08:42:58 GMT X-Originating-IP: [212.1.144.209] From: "Richard Lockwood" To: pgsql-novice@postgreSQL.org, pgsql-sql@postgreSQL.org Subject: Can anybody help me with SQL? Date: Mon, 10 Dec 2001 08:42:58 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 10 Dec 2001 08:42:58.0294 (UTC) FILETIME=[AB39B160:01C18156] X-Archive-Number: 200112/44 X-Sequence-Number: 2588 Hi I was wondering if anyone could help me with the following SQL questions: 1.Which car was rented for the longest single period? (regno) SELECT regno, MAX(datein-dateout) "Longest Single Period" FROM rental group by regno; Although this works - it shows ALL the regno's longest periods - how would i just display the regno? 2. Which car was rented for the longest total period? (regno) 3. Which customers (if any) were born on Monday? (surname) For this question i thought that this would work: SELECT * FROM cust WHERE TO_CHAR(cd_o_b,'DAY') = 'MONDAY' But it never works - it says 'no rows selected' although there are 2 cusotmers born on Monday However if you put wednesday instead of monday or any other day it seems to work correctly Anyone know why this is? 4. Which customer averaged the most miles/day? (surname)(single rental) 5. Which customer averaged the least miles/day? (surname)(single rental) 6. Which customer had to wait for the previous renter to return the car? (surname) 6. What % of rentals are for one day only? 7. Can cars be rented on a Sunday? (i.e. are there any?) (regno) 8. List the total amount of money paid to each garage during this period. 9. What is the average miles driven per day? The rest of the questions just baffle me as i cannot work them out at all. If you can give me any help at all it would be very much appreciated! The data/tables are defined below: SERVICE regno gid sdate smileage scost servrep CAR regno model_id curr_milge next_serv cyear colour MODEL model_id make unit_price mileage_da REPLACE regno gid pno PART partno pdesc RENTAL hireno regno rentalno dateout datein milesout milesin cost CUST custno cname cname_1 cadd_1 ccode cd_o_b GARAGE gid gname gadd Any help would be very much appreciated! Thanks Rickardo _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp