Questions tagged [top-n]
322 questions
1
vote
1 answer
TOPN in PowerBI DAX not arranging values in proper order
I have been running into some issues with the TOPN function in DAX in PowerBI.
Below is the original dataset:
regions sales
--------------
a 1191
b 807
c 1774
d 376
e 899
f 1812
g 1648
h …

Ali Parahoo
- 161
- 2
- 11
1
vote
2 answers
Python dataframe find index of top-5, then index into another column
I have a dataframe with two numeric columns, A & B. I want to find the top 5 values from col A and return the values from Col B held in the location of those top 5.
Many thanks.

ladidalimey
- 69
- 6
1
vote
1 answer
PostgreSQL: How to force db use the "quicksort" sorting method instead of "top-N heapsort"?
Actually, all my question is written in subj-field. It's it somehow possible in PostgreSQL? Probably at server-config level, or can be configured in query, or in properties of table?
I hardly tried to google for it, but got no result. So your help…

WesternTune
- 199
- 1
- 1
- 8
1
vote
0 answers
I need to get Top 10 performing items with an extra filter in Power BI
I have data for incoming telephone numbers to an insurance call centre.
I need to see the top 10 phone numbers called based on the call to quote rate on numbers that have an average daily calls received of 40 or more.
All numbers that have 100%…

Phteven
- 139
- 1
- 13
1
vote
3 answers
How to return the cheapest price?
I have a table named sales and it has 2 columns: Sales_Id and Price. I need to retrieve the cheapest price from the table. The cheapest price is 100. However, it shows only for one Sales_ID whereas I want it to return all 3 entries with the cheapest…

MRS
- 45
- 3
1
vote
2 answers
calculate highest nth salary using sql
I want to calculate highest nth salary in Oracle. I've already done with my solution but on google I found one query doing the same thing.
Here is the query
SELECT *
FROM Employee Emp1
WHERE (N - 1) = (SELECT COUNT(DISTINCT(Emp2.orig_salary))
…

LearnJava
- 372
- 1
- 4
- 16
1
vote
7 answers
SQL - select most frequent value
Im stuck with this, I hope someone can help me with this:
SELECT max(SELECT count(TO_CHAR(hire_date, 'DAY'))
FROM employees
GROUP BY TO_CHAR(hire_date, 'DAY'))
FROM employees;
*
ERROR at line 1:
ORA-00936:…

maik mayo2
- 19
- 3
1
vote
2 answers
Sorting Data by Latest Date, selecting top 10 and charting (v. 10.0.1)
This is the data table that I have created
I need to sort the data by 'April2017' in descending order and then select the top 10 projects.
When we select top10 basis April2017, the output should be
Instead what I get is
Here is what I've tried out…

darkage
- 857
- 3
- 12
- 22
1
vote
1 answer
order by rownum — is it correct or not?
I have a canonical top-N query against an Oracle database suggested by all FAQs and HowTos:
select ... from (
select ... from ... order by ...
) where ronwum <= N
It works perfectly on Oracle 11, i.e. it returns top-N records in the order…

Alexey
- 183
- 1
- 9
1
vote
1 answer
Get both the top-n values and the names of columns they occur in, within each row in dataframe
I have a dataframe like in this one:
df = pd.DataFrame({'a':[1,2,1],'b':[4,6,0],'c':[0,4,8]})
+---+---+---+
| a | b | c |
+---+---+---+
| 1 | 4 | 0 |
+---+---+---+
| 2 | 6 | 4 |
+---+---+---+
| 1 | 0 | 8 |
+---+---+---+
for each row, I need (both)…

Luis Ramon Ramirez Rodriguez
- 9,591
- 27
- 102
- 181
1
vote
2 answers
Select minimal values from two different columns
I have to do a SQL statement to select for each day the min value from a column and when the value Order is the same the Max value from percentage.
Example:
Date Order Percentage …

JohnSmith82
- 55
- 7
1
vote
1 answer
How can I select the "maximum" row from a table?
How can I select the maximum row from a table? What does maximum mean -- well my table has two timestamp columns, TIME1 and TIME2. The maximum column is the one with the latest value for TIME1. If that is not a unique row, then the maximum is the…

jjujuma
- 22,055
- 12
- 44
- 46
1
vote
2 answers
Finding N Largest elements in a column
I have a city table comprising of fields such as ID, Name, CountryCode and Population. I want to find the top N(say N = 5) cities with the largest Population.
A very naive way would be to find the city with the largest population using the MAX()…

Bilal Wasim
- 17
- 6
1
vote
4 answers
Select row with maximum value from table
I have a table with non-unique column auth_id. I need to select the auth_id value with maximum number of entries.
SELECT auth_id, cnt
FROM (SELECT auth_id, COUNT(auth_id) AS cnt
FROM articles_authors
GROUP BY auth_id) articles_num
WHERE cnt =…

ihjn
- 45
- 5
1
vote
1 answer
N Top Record Selection Based on Own SQL Statement in MS-Access
I'm re-writing a small ms-access application to take examinations on.
What they want is for the tests to grab a set of random questions based on how large the exam's size is.
If each exam was a set number of questions, I could just stick the number…

Nitrodist
- 1,585
- 5
- 24
- 34