SQL 查询 7 天前的结果

SQL Query for results from 7 days ago

我有一个 SQL 查询需要更新以提取恰好 7 天前的结果。目前查询正在查看 7 天及之前的结果。我似乎找不到将 > 更改为等于的字符。

SELECT
   distinct(cl.RIID_),
   cl.EMAIL_ADDRESS_  
FROM
   $A$ cl  
JOIN
   $C$ bro 
      ON cl.EMAIL_ADDRESS_ = bro.EMAIL_ADDRESS_   
JOIN
   $D$ cms 
      ON cms.SKU = bro.ITEM  
WHERE
   cl.EMAIL_DELIVERABILITY_STATUS_ = 'D'   
   AND cl.EMAIL_PERMISSION_STATUS_ = 'I'   
   AND (
      cms.CATEGORYNAME = 'Desktop Systems' 
      OR cms.CATEGORYNAME = 'Refurbished Laptops & Tablets' 
      or cms.CATEGORYNAME = 'Laptops & Notebooks' 
   ) 
   AND (
      trunc(bro.ACTIVITY_DATE)
   ) >= (
      Trunc(Cast(From_Tz(Cast(Sysdate As Timestamp ), 'US/Pacific') At Time Zone 'Australia/Sydney' As Date)) - 7
   )

感谢您的帮助!

我看不出将 >= 更改为 = 会如何导致该问题。当我将运算符排除在比较之外时,我得到了这种类型的错误,where a 而不是 where a = b

但是,您应该对 WHERE 子句使用 IN

WHERE cl.EMAIL_DELIVERABILITY_STATUS_ = 'D' AND
      cl.EMAIL_PERMISSION_STATUS_ = 'I' AND
      cms.CATEGORYNAME IN ('Desktop Systems', 'Refurbished Laptops & Tablets' , 'Laptops & Notebooks' ) AND
      trunc(bro.ACTIVITY_DATE) = Trunc(Cast(From_Tz(Cast(Sysdate As Timestamp ), 'US/Pacific') At Time Zone 'Australia/Sydney' As Date)) - 7

并且,删除 distinct 周围的括号。 select distinct 适用于所有被选中的列。括号只会误导您和阅读该查询的其他人。