我在子查询中需要两个文件管理器数据。这是我的子查询
(select CAST(to_char(date_trunc('day', now()-to_date(max(date_time),'yyyy-MM-dd HH24:mi:ss')), 'dd')AS INT) AS monthDiff FROM loyalty_scheme L
JOIN subscribe_merchant S ON (L.scheme_id = S.schemerefid)
JOIN transaction T ON (S.unipoint_customer_ref_id = T.unipoint_customer_ref_id) where (T.unipoint_customer_ref_id IN( select unipoint_customer_ref_id FROM subscribe_merchant where schemerefid = (SELECT scheme_id from loyalty_scheme where minimum_purchase_amount =(SELECT min(minimum_purchase_amount) from loyalty_scheme where merchant_id = 11 )GROUP BY scheme_id) ) )GROUP BY T.unipoint_customer_ref_id )
它将int值作为新列
--------
monthDiff
--------
5
---------
370
---------
我需要将这两个值与另一个子查询进行比较并获得大于值的值。这是另一个子查询
((SELECT CAST(to_char(date_trunc('day', to_date(demoting_time_period,'yyyy-MM-dd HH24:mi:ss')), 'dd')AS INT)*31 AS demortProd from loyalty_scheme where minimum_purchase_amount =(SELECT min(minimum_purchase_amount) from loyalty_scheme where merchant_id = 11)GROUP BY scheme_id ))
它将此作为新列
返回---------------
demortProd
---------------
31
---------------
我需要找到超过31个。
我使用where子句如下:
SELECT *
FROM loyalty_scheme L
JOIN subscribe_merchant S ON (L.scheme_id = S.schemerefid)
JOIN transaction T ON (S.unipoint_customer_ref_id = T.unipoint_customer_ref_id) WHERE (select CAST(to_char(date_trunc('day', now()-to_date(max(date_time),'yyyy-MM-dd HH24:mi:ss')), 'dd')AS INT) AS monthDiff FROM loyalty_scheme L
JOIN subscribe_merchant S ON (L.scheme_id = S.schemerefid)
JOIN transaction T ON (S.unipoint_customer_ref_id = T.unipoint_customer_ref_id) where (T.unipoint_customer_ref_id IN( select unipoint_customer_ref_id FROM subscribe_merchant where schemerefid = (SELECT scheme_id from loyalty_scheme where minimum_purchase_amount =(SELECT min(minimum_purchase_amount) from loyalty_scheme where merchant_id = 11 )GROUP BY scheme_id) ) )GROUP BY T.unipoint_customer_ref_id ) <
(SELECT CAST(to_char(date_trunc('day', to_date(demoting_time_period,'yyyy-MM-dd HH24:mi:ss')), 'dd')AS INT) AS demortProd from loyalty_scheme where minimum_purchase_amount =(SELECT min(minimum_purchase_amount) from loyalty_scheme where merchant_id = 11)GROUP BY scheme_id )
但它会引发错误:
错误:用作表达式
的子查询返回多行
请帮我解决这个错误