Questions tagged [top-n]

322 questions
2
votes
1 answer

how to get top 100 count number for each cell in ggplot2 with geom_bin2d

Before asking, I have read this post, but mine is more specific. library(ggplot2) library(scales) set.seed(1) dat <- data.frame(x = rnorm(1000), y = rnorm(1000)) I replace my real data with dat, the domain of x and y is [-4,4] at this random seed,…
Ling Zhang
  • 281
  • 1
  • 3
  • 13
2
votes
6 answers

Second level Top N SQL server

I have a table with Names, Countries and Status. I want get total by grouping by Names and Status but get only Top 3 Countries. My table: +------+---------+--------+ | Name | Country | Status | +------+---------+--------+ | ABC | US | Open …
Shanka
  • 811
  • 1
  • 7
  • 16
2
votes
2 answers

Third highest salary using rank function in Postgres Sql

Query for third highest salary using rank function select * from ( select emp_sal,row_number()over() as RANK from ( select emp_sal from emp_demo order by emp_sal desc ) )K where K.RANK=3 error coming as…
user2715085
  • 93
  • 1
  • 2
  • 12
2
votes
1 answer

DAX Measure Top N with others in Power BI

I'm developing a report in Power BI where i need to show the Top N Countries by the value of some Produkts they produce. I already managed it to calculate the Top N countries which are variable, but I have no idea how to sum the "Others" in there.…
NerdFlanders
  • 151
  • 2
  • 7
2
votes
3 answers

For each dataframe row, get both the top-n values and the column-indices where they occur

I have 1000x1000 matrix (of floating point numbers) as dataframe. Columns and rows are 0-1000. For each row, I want top-10 highest values and their index information. This turns out to be harder than I thought at first: for row, index in…
impossible
  • 2,380
  • 8
  • 36
  • 60
2
votes
1 answer

Get top-n items of every row in a scipy sparse matrix

After reading this similar question, I still can't fully understand how to go about implementing the solution im looking for. I have a sparse matrix, i.e.: import numpy as np from scipy import sparse arr =…
istern
  • 363
  • 1
  • 4
  • 13
2
votes
1 answer

Pandas: how to test that top-n-dataframe really results from original dataframe

I have a DataFrame, foo: A B C D E 0 50 46 18 65 55 1 48 56 98 71 96 2 99 48 36 79 70 3 15 24 25 67 34 4 77 67 98 22 78 and another Dataframe, bar, which contains the greatest 2 values of…
istern
  • 363
  • 1
  • 4
  • 13
2
votes
2 answers

SQL how to join only first matching row

I don't understand how to join only the first matching row. If I join by a combination of person_id, and dates, the query returns multiple values. In this case, if join returns multiple values, I want only one row from this join to be displayed.…
user3014914
  • 157
  • 2
  • 10
2
votes
2 answers

get random top n rows where n is greater than quantity of rows in table

i'm writing a script that generates random data. i have two tables, one that stores first names, and second that stores surnames. i want to get e.g. 1000 random pairs of first name and surname. i can achieve it using following code: with x as ( …
Konrad
  • 161
  • 1
  • 1
  • 10
2
votes
1 answer

PHP MySQL Returning Different Results From MySQL

When I run a query in MySQL I get an expected result. The query uses MySQL defined variables to group by top n. However, when running in PHP, it seems that the "IF(@businessType=businessType...) is not being evaluated correctly and causing it to…
user2694306
  • 3,832
  • 10
  • 47
  • 95
2
votes
1 answer

SQL Query to return the Top 2 Values

I am trying to return the top 2 most ordered items in our customer database. Below is what I have for the most ordered item but I am having trouble figuring out how to create another column for the 2nd most ordered item. What is the best way to…
marshpipes
  • 134
  • 1
  • 5
2
votes
2 answers

Excluding only one MIN value on Oracle SQL

I am trying to select all but the lowest value in a column (GameScore), but when there are two of this lowest value, my code excludes both (I know why it does this, I just don't know exactly how to correct it and include one of the two lowest…
btalbot
  • 167
  • 9
2
votes
1 answer

Efficiently displaying Top N in Excel PivotTable from SSAS Tabular Model

I have a simple tabular model consisting of a fact table with approx. 20 mio. records (sales transactions) and a dimension table with approx 600.000 records (customers). A typical reporting scenario is to get the top 10 customers over some measure…
Dan
  • 10,480
  • 23
  • 49
2
votes
2 answers

MySQL query: How can I find top 5 images in each brand ?

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
2
votes
2 answers

Get highest value for each group of names

I have the following table as an example: Job_name RunTime AR_job1 100 AR_job2 120 AR_job3 130 EP_job1 100 EP_job2 80 Job field is just text and Runtime is an integer value How do i select the biggest runtime job for…
Smoke
  • 141
  • 1
  • 10