我正在为我的公司建立一个航空货运访问数据库。我有一张有所有机场的桌子,另一张桌子上有空运费用。以下是每个表的字段(a *表示它是键的一部分)
tblAirports
tblAirFreight
空运与机场表连接,在原产地和目的地服务方面都具有参考完整性。
现在,即使是一个简单的选择查询也不能在空运表上工作。我想输入一个原始机场代码(SEA,JFK等)和/或目的地机场代码,以及返回相应的空运费率的查询。我该怎么做?
发布于 2015-02-12 03:19:41
听起来,您想要获得货运表中每个机场列的机场详细信息,所以您只需两次加入机场表。然后根据所提供的参数进行筛选。这只是很难指出正确的方向,您可能需要使用where子句一点。
select *
from
tblAirFreight f
inner join tblAirports o
on o.AirportID = f.OriginAirport
inner join tblAirports d
on d.AirportID = f.DestAirport
where
(f.OriginAirport = @YourOriginAirport or isnull(@YourOriginAirport) = 1)
and (f.DestAirport = @YourDestAirport or isnull(@YourDestAirport) = 1)https://stackoverflow.com/questions/28468452
复制相似问题