为什么我的 SQL 语句给出难以理解的结果 [关闭]

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

当我像那样使用条件时 - 一个结果,如果我使用 case-end 构造或 If 函数,那么结果是不同的并且完全不合逻辑。 Image for Explain Problem

...
Lead(fact_time_tz) Over Win is Null as first_cond,
(diff_date < Max(diff_date) Over(PARTITION BY r.session_uuid) OR is_last_fact = 1) as second_cond,
Lead(fact_time_tz) Over Win is Null
  AND
(diff_date < Max(diff_date) Over(PARTITION BY r.session_uuid) OR is_last_fact = 1)
AS cond,
case when 
   Lead(fact_time_tz) Over Win is Null
      AND
   (diff_date < Max(diff_date) Over(PARTITION BY r.session_uuid) OR is_last_fact = 1)
   then 1 else 0
   end as new_last_fact
   ...

需要帮助!谁能对此给出一个合乎逻辑的解释?! 我有这个输出

is_last_fact first_cond second_cond 条件 new_last_fact
1 1 1 1 1
0 0 1 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 1 0 0
sql mysql case
© www.soinside.com 2019 - 2024. All rights reserved.