[英]Joining Two query
select a.Enquiry_Id,a.Ckeck_In,a.check_Out,a.Hotel_Name,a.Meal_Plan,a.Room_Type,a.Occupancy_Type,a.Room_QT,a.Adults from Accomodation a
where a.Enquiry_Id = 74
select q.Enquiry_Id,q.Start,q1.Stay_At from Quick_Plan q,Quick_Plan q1 where q.Enquiry_Id = 74 and q1.Enquiry_Id = 74 and q.Stay_At = q1.Start
result of 1st query is 第一个查询的结果是
74 2013-08-03 2013-08-04 ADS CP deluxe Double 1 2
and the result of 2nd query is 第二个查询的结果是
74 Ahmedabad Agra
nw i want to combine these two query so that i get the result like 西北我想结合这两个查询,以便我得到像
74 2013-08-03 2013-08-04 ADS CP deluxe Double 1 2 Ahmedabad Agra
In your case the easiest way would be to use CTEs as they won't need much modification. 在您的情况下,最简单的方法是使用CTE,因为它们不需要太多修改。
;WITH FirstCTE AS
(
SELECT a.Enquiry_Id,
a.Ckeck_In,
a.check_Out,
a.Hotel_Name,
a.Meal_Plan,
a.Room_Type,
a.Occupancy_Type,
a.Room_QT,
a.Adults
FROM Accomodation a
WHERE a.Enquiry_Id = 74
),
SecondCTE AS
(
SELECT q.Enquiry_Id,
q.Start,
q1.Stay_At
FROM Quick_Plan q,
Quick_Plan q1
WHERE q.Enquiry_Id = 74
and q1.Enquiry_Id = 74
and q.Stay_At = q1.Start
)
SELECT *
FROM FirstCTE F
JOIN SecondCTE S
ON F.Enquiry_Id = S.Enquiry_Id
I think that the proper way would be: 我认为正确的方法是:
SELECT a.Enquiry_Id,
a.Ckeck_In,
a.check_Out,
a.Hotel_Name,
a.Meal_Plan,
a.Room_Type,
a.Occupancy_Type,
a.Room_QT,
a.Adults ,
q.Start,
q1.Stay_At
FROM Accomodation a
JOIN Quick_Plan q
ON a.Enquiry_Id = q.Enquiry_Id
JOIN Quick_Plan q1
ON q.Enquiry_Id = q1.Enquiry_Id
and q.Stay_At = q1.Start
WHERE a.Enquiry_Id = 74
Assuming that a.Enquiry_Id and q.Enquiry_Id are the keys you use to join, 假设a.Enquiry_Id和q.Enquiry_Id是您用来加入的键,
SELECT a.Enquiry_Id, a.Ckeck_In, a.check_Out, a.Hotel_Name, a.Meal_Plan, a.Room_Type, a.Occupancy_Type, a.Room_QT, a.Adults,q.Start, q1.Stay_At
FROM Accomodation a
INNER JOIN Quick_Plan q ON a.Enquiry_Id = q.Enquiry_Id
INNER JOIN Quick_Plan q1 ON q1.Enquiry_Id = q.Enquiry_Id
WHERE a.Enquiry_Id = 74 AND
q.Stay_At = q1.Start
select
a.Enquiry_Id,
a.Ckeck_In,
a.check_Out,
a.Hotel_Name,
a.Meal_Plan,
a.Room_Type,
a.Occupancy_Type,
a.Room_QT,
a.Adults,
q.Enquiry_Id,
q.Start,
q1.Stay_At
from
Accomodation a,
Quick_Plan q,
Quick_Plan q1
where
q.Enquiry_Id = 74
and q1.Enquiry_Id = 74
and q.Stay_At = q1.Start
and a.Enquiry_Id = 74
try this 尝试这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.