Questions tagged [top-n]

322 questions
0
votes
1 answer

DAX formula for - returning top n revenues

I'm trying to get the top 5 revenues from the column REVENUE in the Table SALES . I have tried this but it's not correct because the expression is suppose to return multiple columns . TOP_N_REV = TOPN(5;FACT_SALES; MAX(FACT_SALES[REVENUE]) ; 0…
Robin
  • 1
  • 2
0
votes
1 answer

Last tuple of time window

I have the following situation stream .keyBy(0) .timeWindow(Time.of(10, TimeUnit.SECONDS)) .sum(1) .flatMap(..) .sink() What I am trying to do is calculate a top N for my time window. The top N for each window…
vriesdemichael
  • 914
  • 1
  • 7
  • 19
0
votes
1 answer

Oracle TOP optimizing

I'm having trouble optimizing a statement. The corrisponding table (INTERVAL_TBL) contains about 11.000.000 rows which causes that statement to take round about 8 seconds on my test system. Even on a dedicated Oracle Server (24gb RAM, 17gb DB size)…
0
votes
2 answers

SQL - Selecting the rows with max timestamp by group

I have this table SITE S_ID BAN COUNT P V TIMESTAMP 23 1 4 1500 0,05 50 10/05/17 09:58:22,609000000 23 3 3 800 0,05 50 10/05/17 09:58:22,736000000 23 2 3 3000 0,05 50 …
Madmartigan
  • 453
  • 1
  • 5
  • 14
0
votes
3 answers

Oracle: I need to select n rows from every k rows of a table

For example: My table has 10000 rows. First I will divide it in 5 sets of 2000(k) rows. Then from each set of 2000 rows I will select only top 100(n) rows. With this approach I am trying to scan some rows of table with a specific pattern.
Raj
  • 23
  • 3
0
votes
3 answers

How can i write a query in PL/SQL to find 3 maximum balance from Account table using cursor?

DECLARE CUSTID NUMBER; ANO NUMBER; BALANC NUMBER; TYP ACCOUNT.TYPE%TYPE; STATU ACCOUNT.STATUS%TYPE; CURSOR S IS SELECT * FROM ACCOUNT WHERE STATUS = 'active'; BEGIN OPEN S; FOR A IN 1..3 LOOP FETCH S …
Eng. Sultan
  • 17
  • 1
  • 7
0
votes
3 answers

Oracle: Getting highest value from two fields (date then value)

I have something like this (date simplified to integer just for the example): Order Date Value 12 5 555 12 5 800 12 2 900 13 3 122 13 4 155 14 1 121 ... ... ... And I'd like to get the order with the highest…
Gabriel
  • 5,453
  • 14
  • 63
  • 92
0
votes
1 answer

oracle - Select first, second and third greatest numbers over multple columns

I have this table structure CLIENT_ID | QTY_A | QTY_B | QTY_C | QTY_D | QTY_E ==================================================== 1 | 20| 21| 19| NULL| 30 ---------------------------------------------------- 2 | …
DylanW80
  • 65
  • 3
  • 12
0
votes
0 answers

Datatype Mismatch - When Sorting Access SQL "Top N" Query

My BASE Code I have a set of data that, where I wanted to grab the Top N with highest SumOfAmount values, FOR EACH Status Detail value. To do this, I used: SELECT [Report_SubstatusVsInsurance_Top3_Q, Part 1].[Status Detail], …
TMY
  • 471
  • 1
  • 7
  • 20
0
votes
2 answers

Using TOP in ORACLE SQL 9

Hello I'am very new to writing SQL and I am trying to find the appropriate way to use TOP in Oracle SQl 9: My example: select * from example e, test t where e.id = t.id and country = 'USA' order by state ASC; What I am trying to do is take the…
user2402107
  • 913
  • 5
  • 22
  • 43
0
votes
1 answer

How to find column index for top n values of a matrix efficiently?

Given a matrix, say m, is there any direct method to find top k values of m and then find exactly which column/row do they belong to. I couldn't find any on SO and hence, putting this question. My try on the above has been this: set.seed(1729) k=5…
0
votes
1 answer

How to Sum an income from TOP 20% of Customers?

Language: DAX Program: Power BI. The problem is simple (not for me though) - i need to know how much of my company's profits come from 20% of its TOP customers. I have a "Customers" list, and "Profit" list. Currently, this list consists of 2035…
0
votes
2 answers

TopN as IEnumerable extension

I am trying to add a general-purpose TopN IEnumerable extension. If the parameter is positive then it is the same as Take() but if it is negative then it should do the same as Take() but then keep yielding immediately sequential values that match…
Simon Hewitt
  • 1,391
  • 9
  • 24
0
votes
1 answer

dplyr top_n remove 0 in summary

How to remove the 0 in the table summary when using top_n with dplyr? library(ggplot2) library(dplyr) data("diamonds") diamonds #set diamonds as data.frame manualTest = diamonds %>% count(cut) %>% top_n(3) table(manualTest$cut) Result Fair…
S12000
  • 3,345
  • 12
  • 35
  • 51
0
votes
3 answers

How to extract second highest row from a table

I have four tables : Batch(batch_id, batch_start_date, batch_strength, course_id) Course(course_id, course_name, course_category, course_fees, course_duration) Enrollment(batch_id, student_id, enrollment_date) Student(student_id, student_name,…