0
我想要做一個排名前10位過濾器是這樣的:如何在Monetdb中實現top n過濾器?
SELECT t0."A" AS d0,
t0."B" AS d1,
t0."C" AS d2,
t0."D" AS d3,
SUM(t0."SA") AS m0,
SUM(t0."SB") AS m1
FROM "mock_table_1" AS t0
INNER JOIN ( //the top 10 filter begin here
SELECT t0."D" AS fd,
SUM(t0."SD") AS top
FROM "mock_table_1" AS t0
GROUP BY t0."D"
ORDER BY top ASC
LIMIT 10
) AS p0u1
ON (t0."D" = p0u1.fd) //the top 10 filter end here
GROUP BY t0."A",
t0."B",
t0."C",
t0."D"
HAVING (SUM(t0."X") <= 100000000)
LIMIT 100
但由於order-by in subquery not avaliable in Monetdb?
所以不工作,我應該怎樣做來實現這個前n個過濾器?
簡化SQL例如:
SELECT t0."A" AS d0,
SUM(t0."SA") AS m0
FROM "mock_table_1" AS t0
INNER JOIN ( //the top 10 filter begin here
SELECT t0."D" AS fd,
SUM(t0."SD") AS top_cond
FROM "mock_table_1" AS t0
GROUP BY t0."D"
ORDER BY top_cond ASC
LIMIT 10
) AS top_filter
ON (t0."D" = top_filter.fd) //the top 10 filter end here
GROUP BY t0."A"
LIMIT 100
我想在這裏做的是A和SUM(SA)從 「mock_table_1」,其中d是在頂部的10 d-會員查詢,和頂10 d-成員是指具有的smallist SUM(SD)
start here? http://stackoverflow.com/questions/30641876/monetdb-sql-method-to-locate-or-match-by-the-nearest-value-without-a-top-or-lim –
我可以給你一個漂亮的簡單的答案,但首先 - 請使用_minimal_例子,即您可以想到的最簡單的表格和查詢,您可以爲其構建「top n filter」查詢。 – einpoklum
@einpoklum對不起,我給出了這個查詢,因爲我認爲它足夠簡單了,我可以簡化它,如果你想。 – luochen1990