oracle找到最畅销的产品和查看详细信息

时间:2015-05-19 14:57:52

标签: sql oracle

问题

显示最畅销的欧洲汽车的详细信息(即制造商名称,型号名称,类型) 模型。

表:

制造商

(manufacturerID, name, region)

模型

(modelNo, name, type, previousModel, manufacturerID)

汽车

(VIN, dateAcquired, yearBuilt, purchasedPrice, askingPrice,
currentMileage, modelNo)

SalesTransaction

(VIN, custID, agentID, dateOfSale, agreedPrice)

我的查询尝试:

select ma.name as "Manufacturer Name", mo.name as "Model Name", mo.type as "Model Type"
from manufacturer ma, model mo, 
inner join car c on mo.modelno = c.modelno
inner join salestransaction st on c.vin = st.vin
where ma.manufacturerid = mo.manufacturerid
having (
        select st.vin
        from salestransaction st
        inner join car c on st.vin = c.vin
        group by st.vin
        order by count(*) desc
        )
rownum=1;

我觉得我犯了多个错误,因为我不太确切知道如何解决这个问题。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

我认为你在寻找类似的东西:

DELETE * FROM tblTransactions
WHERE TxCode = "ICTS" 
  AND transaction_date IN (SELECT transaction_date 
                           FROM tblTransactions
                           WHERE TxCode = "IRFC")`

我没有测试,所以你需要检查语法和表名。