Questions tagged [top-n]

322 questions
3
votes
2 answers

Top n records per group sql in access

I am making some software that tracks the scores of a test. There are multiple users, the details of which are stored in a user table. There is then a progress table which tracks a score with the date and the user who's score it is. I can already…
Huddlespith
  • 123
  • 1
  • 2
  • 8
3
votes
3 answers

Second highest value from Oracle DB's table

According to the tables: USERS (user_name, email, balance) How can I create a query that return the second highest user balance in the most efficient way ? I successes to get this record (but not by the efficient way) with the query: SELECT *…
e o
  • 31
  • 2
3
votes
1 answer

Sorting a DStream and taking topN

I have some DStream in Spark Scala and I want to sort it then take the top N. The problem is that whenever I try to run it I get NotSerializableException and the exception message says: This is because the DStream object is being referred to from…
Ahmed El-Gamal
  • 180
  • 3
  • 18
3
votes
2 answers

Oracle 11g - top N order by is slow

I'm trying to retrieve the last 20 rows by time for users with more than 100K rows in a table with more than 1 million records. The query performance is fine (in ms) when the user has a small number of records. But takes more than 2 minutes to…
3
votes
2 answers

Select or create a view of last 3 articles from more than 1 table

I have two tables. One has articles (article), what are static pages on website. Second has blog articles (blog_article), which articles are shown just in the blog page. Now I want to show latest articles order by date on my homepage. It is easy to…
Patrik Krehák
  • 2,595
  • 8
  • 32
  • 62
3
votes
1 answer

Hive - top n records within a group

I am currently using Hive and I have a table with the fields user_id and value. I want to order the values in descending order within each user_id and then only emit the top 100 records for each user_id. This is the code I am attempting to use: DROP…
Maeve90
  • 345
  • 1
  • 6
  • 14
3
votes
2 answers

Spark: Efficient way to get top K frequent values per key in (key, value) RDD?

I've an RDD of (key, value) pairs. I need to fetch top k values according to their frequencies for each key. I understand that the best way to do this would be using combineByKey. Currently here is what my combineByKey combinators look like object…
sushant-hiray
  • 1,838
  • 2
  • 21
  • 28
3
votes
3 answers

How to produce rank in Oracle

Need to rank the below by salary, with highest salary having rank 1. The RANK column shown is what I'm after: Empname sal address RANK ---------------------------------------------- Ram 3411 45,east road …
anirban
  • 51
  • 1
  • 2
3
votes
1 answer

Oracle linked server top N syntax

I have a linked Oracle 11g server in Microsoft SQL Server 2012. I am trying to retrieve a large linked dataset from Oracle and so to limit it I want to just get the first 100 records. In SQL Server it's simply select top 100 from .... In Oracle…
ErickTreetops
  • 3,189
  • 4
  • 27
  • 37
3
votes
1 answer

Top 10% of sum() Postgres

I'm looking to pull the top 10% of a summed value on a Postgres sever. So i'm summing a value with sum(transaction.value) and i'd like the top 10% of the value
3
votes
5 answers

top 1 case in select statement on TSQL

I am having problem on this query. How can I fix this: select (select case top 1 STATUS when 'Inprocess' then 'Processing' when 'Inworkbin' then 'Waiting In Draft' end from ICS_EMAIL_CONNECTIONS_TRX A where…
cihadakt
  • 3,054
  • 11
  • 37
  • 59
3
votes
3 answers

NHibernate select top N with condition on children using fetch

I have simple User entity: public class User { public virtual int Id { get; set; } public virtual DateTime CreationDate { get; set; } public virtual DateTime ModifiedDate { get; set; } public virtual string Email { get; set; } …
Michael Logutov
  • 2,551
  • 4
  • 28
  • 32
2
votes
1 answer

MySQL query to choose top camera choices based on multiple column values

Okay so I am trying to get some ideas on how to go about determining the top choices of camera I have from the table setup below. This is not a real scenario I am just trying to figure out the best way or some way to go about doing this. So the…
BobPotter
  • 23
  • 4
2
votes
5 answers

Selecting top n elements of a group in Oracle

I have an Oracle table which has a name,value,time columns.Basically the table is for logging purposes to store what are the changes made to a particular name,what was the previous value and what time the change was made. I need to formulate a query…
Harish
  • 3,343
  • 15
  • 54
  • 75
2
votes
2 answers

R dataframe - Top n values in row with column names

I want to sort rowwise values in specific columns, get top 'n' values, and get corresponding column names in new columns. The output would look something like this: SL SW PL PW Species high1 high2 high3 col1 col2 col3 dbl>…
jaykay
  • 71
  • 7