Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple INNER JOINs, searching for records between a year range
    primarykey
    data
    text
    <p>With regards to the following statement:</p> <pre><code>SELECT * FROM explorer.booking_record booking_record_ INNER JOIN explorer.client client_ ON booking_record_.labelno = client_.labelno INNER JOIN explorer.tour_hotel tour_hotel_ ON tour_hotel_.tourcode = booking_record_.tourrefcode INNER JOIN explorer.hotelrecord hotelrecord_ ON tour_hotel_.hotelcode = hotelrecord_.hotelref WHERE booking_record_.bookingdate NOT LIKE '0000-00-00' AND booking_record_.tourdeparturedate NOT LIKE '0000-00-00' AND (hotelrecord_.hotelgroup = "LPL" AND YEAR(booking_record_.tourdeparturedate) BETWEEN YEAR(AddDate(Now(), Interval -5 Year)) AND YEAR(Now()) </code></pre> <p>My MySQL skills are certainly not up to scratch, the actual result set I wish to find is "<strong>a customer who has been to 5 or more LPL hotels in the past 5 years</strong>". So far I haven't got as far as dealing with the count as I'm getting a huge number of results with some 250+ per customer.</p> <p>I assume this is to do with the way I'm joining tables. Schema wise the booking_record table contains a tour reference code, which links to tour_hotel which then contains a hotelcode which links to hotelrecord. This hotelrecord table contains the hotelgroup.</p> <p>The client table is joined to the booking_record via a booking reference and a client may have many bookings.</p> <p>If anyone could suggest a way for me to do this I'd be very grateful and hopefully learn enough to do it myself next time! I've been scratching my head over this one for a few hours now!</p> <p>Customers may have many bookings within booking_record</p> <p>Daniel.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload