我有4个表结构如下:
表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