我有4代表具有以下結構:如何在Oracle中顯示具有最高值的記錄?
表artist
:
artistID lastname firstname nationality dateofbirth datedcease
表work
:
workId title copy medium description artist ID
表Trans
:
TransactionID Date Acquired Acquistionprice datesold askingprice salesprice customerID workID
表Customer
:
customerID lastname Firstname street city state zippostalcode country areacode phonenumber email
第一個問題是藝術家有許多artsold
藝術家的作品已經售出的大多數作品,以及如何。
我的SQL查詢是這樣的:
SELECT * From dtoohey.artist A1
INNER JOIN
(
SELECT COUNT(W1.ArtistID) AS COUNTER, artistID FROM dtoohey.trans T1
INNER JOIN dtoohey.work W1
ON W1.workid = T1.Workid
GROUP BY W1.artistID
) TEMP1
ON TEMP1.artistID = A1.artistID
WHERE A1.artistID = TEMP1.artistId
ORDER BY COUNTER desc;
我對整個事件表,但我只想要只顯示第一行是最高計數我該怎麼做?
我試圖插入WHERE ROWNUM <=1
但它顯示了藝術家ID 1
QNS 2是銷售該藝術家的作品已經產生最高的平均利潤(IE)的平均利潤上的worksby的每個銷售取得藝術家),這是多少錢。
我的SQL查詢:
SELECT A1.artistid, A1.firstname FROM
(
SELECT
(salesPrice - AcquisitionPrice) as profit,
w1.artistid as ArtistID
FROM dtoohey.trans T1
INNER JOIN dtoohey.WORK W1
on W1.workid = T1.workid
) TEMP1
INNER JOIN dtoohey.artist A1
ON A1.artistID = TEMP1.artistID
GROUP BY A1.artistid
HAVING MAX(PROFIT) = AVG(PROFIT);
我不能執行它
我曾嘗試以下,但依然沒能查詢得到它不斷收到錯誤缺少右括號
SELECT A1.artistid, A1.firstname, TEMP1.avgProfit
FROM
(
SELECT
AVG(salesPrice - AcquisitionPrice) as avgProfit,
W1.artistid as artistid
FROM dtoohey.trans T1
INNER JOIN dtoohey.WORK W1
ON W1.workid = T1.workid
GROUP BY artistid
ORDER BY avgProfit DESC
LIMIT 1
) TEMP1
INNER JOIN dtoohey.artist A1
ON A1.artisid = TEMP1.artistid
SO使用Q&A格式,這意味着每個線程有一個問題。然而,在這種情況下,這兩個問題是相關的,因爲它們是同一類問題。 – APC