合并两个SQL查询 [英] Merging two SQL queries
本文介绍了合并两个SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我正在尝试合并两个查询:
Hi everyone I'm trying to merge two queries:
SELECT DISTINCT name,$price
FROM room
JOIN room_booking ON room.room_id=room_booking.room_id
WHERE date_booked<>'$us_date' AND capacity>=$partySize
和
SELECT DISTINCT room_id
FROM room_booking
WHERE room_id NOT IN
(SELECT DISTINCT room_id
FROM room_booking
WHERE date_booked = '$date'
)
合并以上内容的最佳方法是什么,以便最终查询检查room_booking表中不存在的日期,并在房间表超过给定容量的情况下从room表中提取相关信息.
What would be the best way of merging the above so that the final query checks for a date that does not exist in the room_booking table and extracts the relevant information from the room table given it exceeds a given capacity.
推荐答案
这应该完成文本中描述的工作(但我不确定date_booked<>'$us_date'
应该做什么):
this should do the job described in text (but i'm not sure what date_booked<>'$us_date'
is supposed to do):
select name, price
from room
where capacity >= $partySize
and room_id not in
(select room_id
from room_booking
where date_booked = '$date'
)
这篇关于合并两个SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文