[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

SV: [PROGRAMMERING] [SQL] tid, nyeste



Nu har jeg ikke brugt mysql, men oracle og den har en rank og en dense_rank() funktion.

Noget a la

Select *
From
	(select 	id, arrival, departure, room_number, 
		dense_rank() over (order by arrival desc) as rank
	from booking) booking_w_rank
where rank = 1

ville give dig den sidste entry om hvert værelse. Måske vil du tilføje en dato afgrænsning i sub-querien for at undgå fremtidige bookinger.

Regards
Morten Bo Nielsen
Topsil Semiconductor Materials A/S
Linderupvej 4
3600 Frederikssund

Tel, direct: +45 47 36 56 68
Tel, switchboard: +45 47 36 56 00
Fax: +45 47 36 00 01
Email: sslug@sslug


-----Oprindelig meddelelse-----
Fra: Troels Arvin [mailto:sslug@sslug 
Sendt: 10 March 2005 13:55
Til: sslug@sslug
Emne: Re: [PROGRAMMERING] [SQL] tid, nyeste

On Thu, 10 Mar 2005 12:34:30 +0000, Christian Nielsen wrote:

> Hvordan
> ser jeg hvilke værelser, der er ledige fra en given startdato og uendelig
> mange dage frem?

Hvis din tabel hedder "booking", kunne et forslag være:

SELECT room_number
  FROM booking
 WHERE id NOT IN (
       SELECT id
         FROM booking
        WHERE departure>'2004-03-10'
);

Problemet er, at forespørgslen vil ignorere (ikke medtage) værelser, der
aldrig har været book'et. Du kan evt. UNION'e med et subquery, der finder
værelser, der aldrig har været book'et.

Et andet problem kan være, hvis du tillader bookings uden forventet
afrejsedato. Da kan du måske løse det med:

SELECT room_number
  FROM booking
 WHERE id NOT IN (
       SELECT id
         FROM booking
        WHERE departure>'2004-03-10'
           OR departure IS NULL
);

-- 
Greetings from Troels Arvin, Copenhagen, Denmark



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *