Questions tagged [top-n]

322 questions
1
vote
2 answers

Getting Top 5 Results using ROWNUM in Oracle

is there something wrong with my query? I use below to get the first 5 results ordered by AUDIT_ACTN then AUDIT_STAMP. SELECT * FROM (SELECT * FROM TABLE_SAMPLE ORDER BY AUDIT_ACTN ASC,AUDIT_STAMP ASC) WHERE ROWNUM <= 5 And I use this to check if…
user1173805
  • 79
  • 1
  • 3
  • 12
1
vote
1 answer

inner join on table with multiple record

I have two tables as follows table1 column1|column2 ---------------- a1 | c1 ---------------- a2 | c2 table2 column1|column2|column3 ---------------------- 1 | a1 | x ----------------------- 2 | a1 |…
Yagnesh.Dixit
  • 318
  • 7
  • 18
1
vote
3 answers

how to get latest 'n' updated row from a table

Possible Duplicate: Oracle SQL - How to Retrieve highest 5 values of a column i have a table abc, where i have following columns act_id,cust_id,lastUpdatedDate,custActivity. Where act_id is primary key . lastUpdatedDate store last activity done…
Vivek
  • 10,978
  • 14
  • 48
  • 66
1
vote
2 answers

Select rows and group by id and sort for n latest rows (by date)

I have the following set of data returned by a select: date code 23/01/2012 AA123 24/01/2012 AA123 29/01/2012 AA123 06/07/2012 AA123 17/02/2012 BB123 20/02/2012 BB123 04/06/2012 BB123 The select gives all the data…
1
vote
2 answers

SQL questions on these

I have 4 tables. One is called artist. Here is the table structure: artistID lastname firstname nationality dateofbirth datedcease The other table is called work workId title copy medium description artist ID Trans…
1
vote
4 answers

SQL Server: Why do these queries return different result sets?

Query 1 = select top 5 i.item_id from ITEMS i Query 2 = select top 5 i.item_id, i.category_id from ITEMS i Even if I remove the top 5 clause they still return different rows. if I run "select top 5 i.* from ITEMS i" this returns a completely…
Storm
  • 4,307
  • 11
  • 40
  • 57
1
vote
1 answer

Return N results for different groups with additional condition oracle sql

How would I be able to N results for several groups in an oracle query. See the following table for an example: ID Team Auditor 1 Tm1 Jill 2 Tm2 Jill 3 Tm1 Jill 4 Tm2 Jack 5 Tm2 Jack 6 …
bawpie
  • 467
  • 4
  • 12
  • 27
0
votes
1 answer

Top N products type in every month - BIGQUERY

I have to create a TOP 10 of gross revenue/country/month with the statement : dimensions: date (month) site_country product type metric: gross_revenue (only top 10 products type per country/month) I have tried a big query program below between 2…
user19774345
0
votes
2 answers

Power Bi: how to parameterize Top N visual level filter

Since PowerBI don't support Top N filter on page level, I want to use N as a parameter to change it at once per multiple visuals. Is it possible? P.S.In this video (9:15) solution for more complex case is provided. In the end of this article sample…
Denis
  • 625
  • 1
  • 8
  • 28
0
votes
1 answer

Looking for a function to fined the mean of the top n values (not rows!) conditionally and return the number and not a dataframe

I have a large data frame: percentage_activity # A tibble: 4,437 x 3 # Groups: DATETIME [87] DATETIME ID COUNT 1 2020-06-07 00:00:00 Bagheera NA 2 2020-06-07 00:00:00 Bagheera2 …
Maya Eldar
  • 49
  • 5
0
votes
1 answer

Tracking Changes in TOP N Products from Year to Year using DAX in PowerBI

Let's say I set my slicer value to N = 3 and Year = 2021, I would like to return a table that shows which products were in the Top 3 in the selected year 2021 but not in the prior year 2020. So if the TOP 3 products in 2021 were Bananas, Oatmeal and…
0
votes
2 answers

Postgres SQL - Top 2 records GROUP BY and COUNT

I have a some data in the following…
MB4ig
  • 65
  • 5
0
votes
2 answers

Dplyr: Group by and then return top n based on different conditons

I have been trying to solve the problem of grouping my data (by Loan Number) and then returning the one row per group based on either the highest or lowest value of a certain column (here it is the Filter column) based on differing conditions. I…
Matthew Oldham
  • 187
  • 1
  • 13
0
votes
3 answers

Determine which year-month has the highest and lowest value

Here's my first query to shows the number of customers added per year-month select count(name) AS CUSTOMER, extract(year from create_date) as yr, extract(month from create_date) as mon from x group by extract(year from create_date),…
Jeanne
  • 1
  • 1
0
votes
1 answer

Pandas compute mean over top n records of a group

Suppose I have pandas DataFrame like this: id value 0 1 1 1 1 2 2 1 3 3 2 4 4 2 3 5 2 2 6 2 1 7 3 1 I'd like to compute the mean per id over the first 2 records and and append the resulte…
McDizzy
  • 189
  • 11