“where”后面是否可以使用2个“and”过滤器?

问题描述 投票:0回答:1

我有一项家庭作业任务,描述如下:

The following information must be displayed: 
• Flight ID;
• Delivery airport code;
• Arrival airport code;
• Scheduled departure date and time;
• Actual departure date and time;
• How long the flight was delayed;
• Minimum departure delay time for departure at the airport;
• Average departure delay time for departure at the airport;
• Maximum departure delay time for departure at the airport;
The data must be displayed only for those flights where information about the actual departure date                     
and time exists, and the delay time is 1 minute or more.

然后我写了查询:

     select *
 ,flight_id 
 ,departure_airport
 ,arrival_airport 
 ,scheduled_departure 
 ,actual_departure
 ,avg(actual_departure - scheduled_departure)
 ,max(actual_departure - scheduled_departure)
  from booking.flights
  where actual_departure is not null
  and actual_departure != ' ' // to filtrate column "actual_departure" by fields which 
 consist of ' '
  and (actual_departure - scheduled_departure) > '1'
  group by flight_id
  ;
  

但是我注意到了 1 个问题 - 在描述中被告知列

actual departure
中的“NOT NULL”字段,但我确信数据中可能有很多字段不是 NULL 而是带有“”。

我怎样才能过滤这些字段?

当我尝试使用第二个

AND
时,DBeaver 显示错误

SQL 错误 [22007]:错误:时间戳类型的输入语法无效 时区:“”。

使用“”代替''没有帮助。

在使用“WHERE”和第一个“AND”后,我无法获得有关二次使用运算符“AND”的信息。需要帮助了解我可以使用哪种方法按字段过滤列

actual_departure
由 ' ' 组成。

sql postgresql filter dbeaver
1个回答
1
投票

第一,谈论“和过滤器”是没有意义的。 “And”不是过滤器,而是逻辑运算,可用于构建用作 WHERE 条件一部分的表达式。 在您的示例中,WHERE 子句是

where actual_departure is not null
  and actual_departure != ' ' 

第二,您是否阅读了收到的实际错误消息?

invalid input syntax for type timestamp with time zone: " ".

显然

actual_departure
的类型是
timestamp with time zone
。 因此它不能等于单个空格,因为这不是这样的列可以首先保存的值。

© www.soinside.com 2019 - 2024. All rights reserved.