我正在使用oracle中的sqlplus,并试图找出创建客户列表的方法,并根据以下条件对它们进行分类:
然后创建一个预期的输出(我已将其作为图像附加)。

为此,我也附上了ERD。
这就是我到目前为止所拥有的。
SELECT DISTINCT first_name "First",
surname "Last",
customer_number "Cust #",
account_type "# of Accts"
FROM ( SELECT first_name,
surname,
customer_number,
account_type
FROM wgb_customer
JOIN wgb_account USING (customer_number)
JOIN wgb_account_type USING (account_type)
ORDER BY account_type);请帮帮忙!这是预期的输出!
First Last Cust# # of Accts Level
----------------------------------------------------------------
Peter Chen 2566217 3 Growing
Byron Griffith 1113004 1 Entry Level
Patricia Lee 9871332 1 Entry Level
Henri Poincare 1113501 3 Growing
John Synge 1112401 2 Growing 发布于 2019-02-22 02:09:33
这听起来像是使用case表达式进行聚合:
select c.first_name, c.surname, c.customer_number,
count(*) as num_accounts,
(case when count(*) = 1 then 'Entry Level'
when count(*) <= 3 then 'Growing'
else 'Mature'
end) as level
from wgb_customer c join
wgb_account a
using (customer_number)
group by c.first_name, c.surname, c.customer_number;https://stackoverflow.com/questions/54818346
复制相似问题