Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 22nd, 2003, 09:24 AM
Registered User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please Help with advanced sql query

I have a database that shows seat utilisation in a computer class. We hold 3 sessions daily, ie am, pm, evening. On the booking they can book for any seesion and have a seat also a seat number 1 -8. I want to be able to create a query that will eventually show up on a web page , which shows that session = am has some seats booked and some available. The session data lies in a session_booking table, that contains the following columns.
Session_date, Session _name, seat number, booked by
01/04/2003, am, 1, voucher
01/04/2003, pm, 5, voucher
01/04/2003, evening, 3, Club

I dont really want to re-organise the table.

I would like this solved sharply as i have been at it for about 3 weeks.

Mike
  #2 (permalink)  
Old June 22nd, 2003, 03:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

First off, it is helpful in this sort of situation to have a table of the valid seat numbers. I'll assume the existence of this table; we'll call it SeatNumbers; it has a single column 'SeatNumber'.

Assuming you provide the date and session name as parameters, then a query which lists the available seats for a given date and session is:
Code:
-- @sd is the session date, @sn is the session name

SELECT @sd, @sn, SeatNumber
   FROM SeatNumbers
   WHERE SeatNumber NOT IN (SELECT seat_number FROM session_booking SB
            WHERE SB.session_date=@sd
              AND sb.session_name=@sn);
I find it very handy to have a sequence number table available for these sorts of purposes. I create a table of integers and populate it with the numbers from 1 to how ever many I think I need. I use them for all sorts of random numbering purposes like this.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com


Similar Threads
Thread Thread Starter Forum Replies Last Post
sql query i need seearam MySQL 7 November 30th, 2008 03:14 AM
Help with C# and SQL query Codeman1234 C# 2005 19 April 24th, 2008 05:26 AM
sql advanced option not available hertendreef Visual Web Developer 2008 5 February 21st, 2008 05:37 PM
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
SQL query? spark SQL Language 4 June 15th, 2005 08:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.