Questions tagged [top-n]
322 questions
4
votes
3 answers
Stored Procedure Maximum Pattern Match
This is my stored procedure in Oracle:
CREATE OR REPLACE PROCEDURE execute_cproc ( callnum IN VARCHAR2
, RESULT OUT VARCHAR2)
AS
vara_val NUMBER;
varb_val NUMBER;
BEGIN
SELECT a_val, b_val
…

VJS
- 2,891
- 7
- 38
- 70
4
votes
3 answers
Query to get top product gainers by sales over previous week
I have a database table with three columns.
WeekNumber, ProductName, SalesCount
Sample data is shown in below table. I want top 10 gainers(by %) for week 26 over previous week i.e. week 25. The only condition is that the product should have sales…

milan m
- 2,164
- 3
- 26
- 40
4
votes
5 answers
How to find the employee with the second highest salary?
Is there any predefined function or method available to get the second highest salary from an employee table?

Anil
- 665
- 1
- 10
- 14
4
votes
3 answers
MSSQL Get max value from multiple columns by an ID
I've come across many similar posts on this but none I've found got this specific.
Here's my sample data:
ID CID NARID NATID NADate EID AEDate
1 1655 1 4 12/1/12 202 6/4/14 11:37:01
2 …

versionke
- 43
- 3
4
votes
1 answer
mysql query, how can i get top 5 downloads with GROUP_CONCAT
the following data in MySql table.
brand_id|image_id|downloads
--------|--------|---------
8 |9 |8
35 |2829 |4
28 |2960 |3
28 |2961 |3
28 |3041 |3
35 |2831 |3
28 |2965 …

Girish
- 11,907
- 3
- 34
- 51
4
votes
2 answers
top-N query doing too much work in spite of STOPKEY optimization
This is going to be long, so here's a quick summary to draw you in: my
top-N query with COUNT STOPKEY and ORDER BY STOPKEY in its plan is
still slow for no good reason.
Now, the details. It starts with a slow function. In real life it
involves…
user2404501
3
votes
0 answers
Top n loudest audio packet forwarding from media in a conference
I have an SFU media which just relays audio packets to everyone except the sender. Now for a large-scale conference, it is not a good idea to send all participant's audio packets to everyone if the participant count goes beyond 50-100 (let's assume…

Nafiul Alam Fuji
- 407
- 7
- 17
3
votes
1 answer
select top n values by group with n depending on other value in data frame
I'm quite new to r and coding in general. Your help would be highly appreciated :)
I'm trying to select the top n values by group with n depending on an other value (in the following called factor) from my data frame. Then, the selected values shoud…

kate99
- 31
- 3
3
votes
2 answers
PyTorch: Zero all elements of vector except top k?
I am trying to create a new activation layer, let’s call it topk, that would work as follows. It will take a vector x of size n as input (result of multiplying previous layer output by weight matrix and adding bias) and a positive integer k and…

user40739
- 91
- 5
3
votes
1 answer
How to extract the first n rows per group from a Spark data frame using recent versions of dplyr (1.0), sparklyr (1.4) and SPARK (3.0) / Hadoop (2.7)?
My attempts with top_n() and scale_head() both failed with errors.
An issue with top_n() was reported in https://github.com/tidyverse/dplyr/issues/4467 and closed by Hadley with the comment:
This will be resolved by #4687 + tidyverse/dbplyr#394…

jimbod119
- 2,871
- 1
- 6
- 11
3
votes
2 answers
dplyr - How to filter the top n groups with more (sum) sales?
I am using dplyr on R and I am trying to filter a tibble which contains transactional data.
The columns of my interest are "Country" and "Sales".
I have a lot of countries and for exploration purposes I want to analyze only the TOP 5 countries with…

spcvalente
- 136
- 3
- 14
3
votes
2 answers
PostgreSQL query rows with least null value on columns
How can I query rows where the output would be the rows with least null value on the columns?
My data is:
ID | col1 | col2 | col3 | col4
-----------+----------+-----------+-----------+-----------
1 | Null …

gdmplt
- 33
- 1
- 4
3
votes
2 answers
SQL How to return the record with the most recent date and also highest int value
I have to return the most recent row in a SQL database, grouped by CallID. The 'most recent' in this instance means the most recent DepartureDate and the highest Departuretime (int) on that date. See below example for your reference:
set dateformat…

Naz
- 525
- 2
- 9
- 21
3
votes
3 answers
Select the n most frequent values in a variable
I would like to find the most common values in a column in a data frame. I assume using table would be the best way to do this? I then want to filter/subset my data frame to only include these top-n values.
An example of my data frame is as follows.…

Fiona
- 477
- 1
- 9
- 18
3
votes
1 answer
top_n() not selecting n
Aim: To plot the first 20 countries in descending order
Problem: When using the top_n function, it insists in selecting all and not just the top 20.
Here is my code:
#Omit missing values
na.omit(kiva_loans)%>%
#Group by country label
…

delcast
- 496
- 1
- 5
- 16