I have an big problem with an SQL Statement in Oracle.
(我在Oracle中使用SQL语句遇到了很大的问题。)
I want to select the TOP 10 Records ordered by STORAGE_DB which aren't in a list from an other select statement. (我想选择STORAGE_DB排序的前10条记录,这些记录不在其他select语句的列表中。)
This one works fine for all records:
(此记录适用于所有记录:)
SELECT DISTINCT
APP_ID,
NAME,
STORAGE_GB,
HISTORY_CREATED,
TO_CHAR(HISTORY_DATE, 'DD.MM.YYYY') AS HISTORY_DATE
FROM HISTORY WHERE
STORAGE_GB IS NOT NULL AND
APP_ID NOT IN (SELECT APP_ID
FROM HISTORY
WHERE TO_CHAR(HISTORY_DATE, 'DD.MM.YYYY') = '06.02.2009')
But when I am adding
(但是当我添加)
AND ROWNUM <= 10
ORDER BY STORAGE_GB DESC
I'm getting some kind of "random" Records.
(我正在获取某种“随机”记录。)
I think because the limit takes in place before the order. (我认为是因为限价是在下订单之前进行的。)
Does someone has an good solution?
(有人有好的解决方案吗?)
The other problem: This query is realy slow (10k+ records) (另一个问题:这个查询真的很慢(超过10k条记录))
ask by opHASnoNAME translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…