我只想输出那些记录,对于相同的名称customer\u name,cust\u valid='i'和cust\u valid='a'
我试过这样做,但是客户的rezult只有记录'a'在这里输入代码
SELECT c.cust_first_name ||' '|| c.cust_last_name AS CUSTOMER_NAME,
to_number(SUBSTR(c.cust_income_level, INSTR(c.cust_income_level, '-')+2), '999999') as UPPER_INCOME_LEVEL,
sum(s.amount_sold) as TOTAL_AMOUNT,
(CASE WHEN c.cust_credit_limit <= 1500 THEN 'Low_limit'
ELSE 'High_limit'
END) credit_limit_level,
c.cust_valid
FROM SH.customers c
JOIN sh.sales s on c.cust_id = s.cust_id
WHERE c.cust_valid = 'A' AND c.cust_income_level like '%-%'
GROUP BY c.cust_first_name, c.cust_last_name, c.cust_income_level, c.cust_credit_limit, c.cust_valid
HAVING SUM(s.amount_sold) > (c.cust_credit_limit * 50)
ORDER BY UPPER_INCOME_LEVEL DESC, CUSTOMER_NAME;
3条答案
按热度按时间cedebl8k1#
你需要使用
EXISTS
中的子句WHERE
条件如下:s5a0g9ez2#
如果我正确地跟踪了您,您可以通过修改
having
条款:和cust\u valid='a'
pgky5nke3#
我试过了,但没有结果。我认为我的情况不正确。
我必须解释。。。修改查询以显示客户机的名称(customer\u name),其中有cust\u valid='a'的行和cust\u valid='i'的行作为单独的结果。