Questions tagged [top-n]

322 questions
-1
votes
2 answers

How to find the largest range between related dates in a column?

I have a database where there are bands in one column and another column where there are release dates of their albums, how do i find the oldest band based off of the difference between their release dates? I.e. the oldest band is not Band1 because…
-1
votes
2 answers

Show tasks which have taking the longest time sql

I need to show the tasks which have taken the longest to complete. So far I have: (But I’m aware that it isn’t working as when I round the tables my results show both 1 and 2 months when it should be only showing 2, as 2 months is the longest…
-1
votes
3 answers

how to find the longest N words from a list, using python?

I am now studying Python, and I am trying to solve the following exercise: Assuming there is a list of words in a text file, My goal is to print the longest N words in this list. Where there are several important points: The print order does not…
Itay Av
  • 69
  • 3
  • 10
-1
votes
5 answers

ORACLE SQL Second Maximum Salary

How to find Second Maximum salary drawn by the employee from Employees table. Whether is it possible to find it through ROWNUM function. example table: S.no Name employee_id salary 201 Steven 100 1000 202 …
karthik_19942017
  • 49
  • 1
  • 2
  • 6
-1
votes
4 answers

SQL select to display latest record

So here is a case where one of the column in a table has same values for multiple records but the Date column has incremental values. ID| PAY_CODE| RATE | Date --------------------------------- 1 | 1111 | 50 | 2017-01-01 2 | 1111 | 50 …
intruder
  • 417
  • 1
  • 3
  • 18
-1
votes
1 answer

How to pivot table by month and display top 10 by total amount only

I have a dynamic dataset that returns data from today and a year back. How can I pivot this data and return only top 10 Description by NetWrittenPremium? I know how to perform static pivot, but confused how would I do it in this case. …
Serdia
  • 4,242
  • 22
  • 86
  • 159
-1
votes
1 answer

hive - Top N with multiple measurements in one query?

The sample table value measurement1 measurement2 -------|-------------|----------- value1 1 **2** value2 **3** **3** value3 **2** 1 Then find top 2 highest value, I want to get the output below: top 2…
Wayne
  • 29
  • 4
-1
votes
2 answers

Oracle SQL regarding subquery condition

I got a question about Oracle SQL using the subquery. With a table as shown below the question is. "Write a query that will display the customer(s) that referred maximum number of customers." You can see a customer with max number of reference…
-1
votes
2 answers

Top N percent Desc and Top M percent Asc

I am trying to get top 5 customertypes and show data for each 5 customer types, The balance (which can be any amount) I show them as "Other Customer Types". my issue is since the rows can be random and not perfectly divisible by a number then there…
-1
votes
2 answers

Oracle sql fiding shipping delay

can i know how i could write the sql statement in listing the shipping city and state for the order that has the longest shipping delay. I not sure need use the function Max in where
Jayam Koko
  • 49
  • 1
  • 9
-1
votes
1 answer

T-SQL Top X, All Other - Multiple Constraints

I have a massive data pull, and I have four keys I want to be able to sort on in particular. pk.Formula.SPEEDCODE pk.Formula.THERAPEUTIC_CLASS pk.RxFill.PATIENT_PRICE pk.RxFill.SHIP_DATE Essentially, for each THERAPEUTIC_CLASS, I want to be able to…
Don Ford
  • 105
  • 10
-1
votes
3 answers

TopScore or FilteringMap map, sorted on key

For lack of a better name, I am calling the data structure I am looking for as a "TopScoreMap". Here is the requirement. First, the size of the map is fixed. For instance, the map only needs to retain top n entries that would be thrown at this map.…
ring bearer
  • 20,383
  • 7
  • 59
  • 72
-2
votes
3 answers

SQL - Sum Top N values in each row

This is my SQL table. +-------+------+------+------+------+ | name | q1 | q2 | q3 | q4 | +-------+------+------+------+------+ | Alex | 5 | 4 | 10 | 7 | | Brown | 7 | 6 | 4 | 1 | | Chris | 10 | 10 | 9 | 10…
S. Ryu
  • 1
-2
votes
1 answer

How to fetch the first comment date of users in comments table

have a comments table and need to get the first comment date (first inserted record) of each users in the table. Output will be : user_id first_comment_date
waleedazam
  • 357
  • 2
  • 12
-2
votes
2 answers

Using top N Employees

I need a query to get Top N employees working on every project in a specific month based on working hours. And I need the same query for all time (without specifying a month). I get two hints first Hint: Use Substitution variables to prompt the…
1 2 3
21
22