我可以查看我的資料有問題,因爲我想在1組合2行,查看和同桌
IDFlight | Dep1 | Des1| Date | IDFlight2 | Dep2 | Des2 | Date | Price
---------+------+-----+-------+-----------+------+------+--------+--------
2 | AYT | PRN |20.3.15| 3 | PRN | AYT | 27.3.15| 150
2 | AYT | PRN |20.3.15| 4 | PRN | AYT | 30.3.15| 150
1 | AYT | PRN |23.3.15| 4 | PRN | AYT | 30.3.15| 150
1 | AYT | PRN |17.3.15| 3 | PRN | AYT | 27.3.15| 150
所以搜索查詢與日期+ - 4天都爲2個航班。
在我的情況下,每個航班都單獨登記在航班表中,每個航班都有他的航班號和他的航班號,日期和定價(例如,返程和單程)。 現在這裏的問題是,當用戶選擇返回選項時,將在一行中顯示2個航班(航班1去目的地,航班2從目的地返航),在例子中的日期線之間也有差異圖片。
我想要實現的是顯示上例中的數據,即每個「單向」記錄應該與「返回」記錄匹配。即使第一個數據重複。
我已經做了很多的研究,但沒有結果,也 我試圖用一個看法,但沒有成功
我想聯盟沒有做成功。
@prmDepDay int, @prmDesDay int, @prmDateDep datetime, @prmFrom int, @prmTo int,
@prmDateRe datetime, @prmFromRe int, @prmToRe int, @prmTotalRe int
AS
BEGIN
DROP TABLE departureflights
SELECT TOP(100) PERCENT
t_flights.idflight,
t_flights.flightnumber,
t_departureairport.depairportname,
t_destinationairport.desairportname,
t_flights.startdate,
t_flights.totalseats
INTO departureflights
FROM t_flights
INNER JOIN t_departureairport
ON t_flights.iddepartureairport = t_departureairport.iddepartureairport
INNER JOIN t_destinationairport
ON t_flights.iddestinationairport = t_destinationairport.iddestinationairport
INNER JOIN t_flightdirections
ON t_flights.iddirection = t_flightdirections.iddirection
WHERE t_departureairport.iddepartureairport = @prmFrom
AND t_destinationairport.iddestinationairport = @prmTo
AND startdate >= Dateadd(day,[email protected],@prmDateDep)
AND startdate <= Dateadd(day,@prmDepDay,@prmDateDep)
--and TotalSeats>= @prmTotal
ORDER BY t_flights.startdate
DROP TABLE returnflights
SELECT t_flights.idflight,
t_flights.flightnumber AS ReFlightNumber,
t_departureairport.depairportname AS ReDepAirportName,
t_destinationairport.desairportname AS ReDesAirportName,
t_flights.enddate ,
t_flights.totalseats
INTO returnflights
FROM t_flights
INNER JOIN t_departureairport
ON t_flights.iddepartureairport = t_departureairport.iddepartureairport
INNER JOIN t_destinationairport
ON t_flights.iddestinationairport = t_destinationairport.iddestinationairport
INNER JOIN t_flightdirections
ON t_flights.iddirection = t_flightdirections.iddirection
WHERE t_departureairport.iddepartureairport = @prmFromRe
AND t_destinationairport.iddestinationairport = @prmToRe
AND enddate >= Dateadd(day,[email protected],@prmDateRe)
AND enddate <= Dateadd(day,@prmDesDay,@prmDateRe)
AND totalseats>= @prmTotalRe
ORDER BY t_flights.enddate
也許交叉連接可以幫助你? – Disappointed
您有這篇文章被列爲C#。您可以從C#執行存儲SQL過程,然後返回結果。在C#中,這可以比使用SQL查詢更容易完成。執行連接後,您可以從單個「連接結果」創建多行。如果您可以發佈存儲的SQL過程的結果,我可以提供幫助。 – jdweng