我真的不明白?!你想要做什麼,但我認爲它要麼是你想要的每位藝術家的客戶數量
Select A.Lastname ||''|| A.FirstName as Artist_Name
COUNT(*) as nb_cust
from dhey.ARTIST A
LEFT outer JOIN Dhey.CUSTOMER_ARTIST_INT B on A.ArtistID = B.ArtistID
group by A.ArtistID, A.Lastname ||''|| A.FirstName
order by nb_cust desc
或者你想要的客戶的最大數量整體和聯繫,爲您的藝術家......這是一個線交叉的產物。
Select A.Lastname ||''|| A.FirstName as Artist_Name
nb_cust_max
from dhey.ARTIST A
cross join ( select max(nb_cust) as nb_cust_max
from ( select count(*) as nb_cust
From Dhey.CUSTOMER_ARTIST_INT
group by ARTISTID
)
)
我關閉了嗎?或完全錯誤?
否則,由MatBailie建議,你可以添加缺少的領域
Select A.Lastname ||''|| A.FirstName as Artist_Name from dhey.ARTIST A
LEFT JOIN
(SELECT * FROM(
SELECT ARTISTID, COUNT(*) As Num_of_Customer From Dhey.CUSTOMER_ARTIST_INT CAI
GROUP BY ARTISTID
ORDER BY COUNT(*) desc) WHERE ROWNUM = 1) B on A.ArtistID = B.ArtistID;
你可能想'選擇ArtistID,COUNT(*)'在最內層查詢... – MatBailie