Reply
complex query help plz
Old 04-24-2007, 08:12 PM complex query help plz
Novice Talker

Posts: 6
User selects start and end date....from 25 to 27....

+---------+------+-----------+
| day_Num | qty | room_Type |
+---------+------+-----------+
| 25 | 2 | single |
| 25 | 0 | double |
| 25 | 0 | ensuite |
| 26 | 6 | single |
| 26 | 13 | double |
| 26 | 5 | ensuite |
| 27 | 1 | single |
| 27 | 1 | double |
| 27 | 1 | ensuite |
+---------+------+-----------+

room_Type = double and ensuite has ZERO qty....so all the related data with double and ensuite...should not be printed...so the OUTPUT should be:

+---------+------+-----------+
| day_Num | qty | room_Type |
+---------+------+-----------+
| 25 | 2 | single |
| 26 | 6 | single |
| 27 | 1 | single |
+---------+------+-----------+

And from here then... the lowest qty should be printed out, so the FINAL OUTPUT should be:

+---------+------+-----------+
| day_Num | qty | room_Type |
+---------+------+-----------+
| 27 | 1 | single |
+---------+------+-----------+

Anyone know what the query should be?
hola is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 04-25-2007, 04:54 AM Re: complex query help plz
chrishirst's Avatar
Super Moderator

Posts: 12,752
Location: Blackpool. UK
if it's for MySQL then;

SELECT day_num,qty,room_type FROM rooms WHERE day_num BETWEEN 25 AND 27 AND qty > 0 ORDER BY qty ASC LIMIT 1;

for SQL server

SELECT TOP 1 day_num,qty,room_type FROM rooms WHERE day_num BETWEEN 25 AND 27 AND qty > 0 ORDER BY qty ASC ;
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to complex query help plz
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11770 seconds with 13 queries