Sql 如何处理返回多个值错误的子查询?

Sql 如何处理返回多个值错误的子查询?,sql,oracle,Sql,Oracle,是否有其他方法来编写此查询,使其不会出现错误 select sum(Travelled_value) from travel_table where customer_id=(select distinct f.CUSTOMER_ID as agg from SEGMENT_table f JOIN bookin_table t ON f.CUSTOMER_ID=t.CUS

是否有其他方法来编写此查询,使其不会出现错误

select sum(Travelled_value) 
from travel_table 
where customer_id=(select distinct f.CUSTOMER_ID as agg 
                   from SEGMENT_table f 
                   JOIN bookin_table t 
                   ON f.CUSTOMER_ID=t.CUSTOMER_ID 
                   where t.booking_date BETWEEN sysdate 
                   AND sysdate+21 and f.type='NEW';)

这三个表的customer_id是公共的。

我不知道这是否有效,但它解决了许多问题:

select sum(tt.Travelled_value)
from travel_table tt
where tt.customer_id in (select f.CUSTOMER_ID 
                         from SEGMENT_table f JOIN 
                              booking_table t
                              ON f.CUSTOMER_ID = t.CUSTOMER_ID
                         where t.booking_date between sysdate and sysdate+21 and
                               f.type = 'NEW'
                        );
注:

  • 在查询的中间有一个分号。它在结尾
  • 子查询中的
    不需要
    select distinct
  • 您正在使用
    sysdate
    并将其与日期进行比较。您确定不想要
    trunc(sysdate)
    sysdate
    有一个时间组件

编辑您的问题并显示错误。您可能希望在子查询中使用
,而不是子查询中的
=
。将
何处客户id=
替换为
何处客户id
SELECT SUM(Travelled_value)
FROM travel_table
WHERE customer_id in
  (SELECT  f.CUSTOMER_ID 
  FROM SEGMENT_table f
  JOIN bookin_table t
  ON f.CUSTOMER_ID=t.CUSTOMER_ID
  WHERE t.booking_date BETWEEN trunc(sysdate) AND trunc(sysdate+21)
  AND f.type='NEW'
  );