Questions tagged [top-n]

322 questions
0
votes
1 answer

MS Access SQL SELECT TOP QUERY

I need some assistance on the SELECT TOP Queries and whether it will be easier to write the code in VBA or carry on using SQL. I have a table (StockSheet) which has 17 columns and over +500 records, the only relevant fields for the Queries are…
0
votes
0 answers

How to create a stacked bar chart showing only Top N rows (values) per column

I'm new to Python, and working on this project looking at deals won by an IT company. For the data below I'd like to create a stacked bar chart that shows only the top 5 'VP-Manager' values per 'Client Category' i.e. the top 5 'VP-Manager' who have…
Tanvikc
  • 1
  • 1
0
votes
2 answers

Select top N items per group ms-Access - MORE "Ns"

I find very similar questions to mine, but noone contains my problem. I work with ms-Acces: I need to create a Rank query of my groups, selecting the TOP N Profits for each group. THE PROBLEM is that this "N" is not the same for each group, but I…
vale bra
  • 21
  • 4
0
votes
1 answer

hive Expression Not In Group By Key (group by - having)

I need to execute this query to create a table of the average growth rate for each state and industry create table industry_growth as select state,sub_industry, avg(growth_percent)ind_growth from company_growth group by state, sub_industry having…
0
votes
1 answer

is there a way of keeping all obs condtion on top_n value from another column

i need to find a way using tidyverse to keep all obs. but filtering all other observation than the top_n values from a column. example: Name| title | rank John| xxxxxx | 1 John| yyyyyyy | 1 John| zzzzzz | 1 max | xxxxxx | 3 max |…
Cafi
  • 1
0
votes
1 answer

Choose top three price points by category in Power BI

I'm working on a Power BI report, and I have a dataset with a large list of prices broken down by company, product class and product name. What I'd like to do is display the top three prices in each class, and show which product name, and which…
Alec Zrike
  • 37
  • 6
0
votes
1 answer

How do I select top rows in SQL

I have a code that outputs Department Names and their number of workers. SELECT department_name,COUNT (employee_id) FROM EMPLOYEES JOIN DEPARTMENTS ON employees.department_id=departments.department_id GROUP BY department_name ORDER BY…
Nathan Klero
  • 49
  • 1
  • 1
  • 7
0
votes
2 answers

Select Last Rows with Distinct Field

I have a table with the following schema: id itemid date some additional data 1 1000 10/12/2020 a 2 1000 10/12/2020 b 3 1002 09/12/2020 c 4 1001 07/12/2020 d 5 1000 05/12/2020 e 6 1005 …
Alk
  • 5,215
  • 8
  • 47
  • 116
0
votes
1 answer

get error in select the nth column in oracle

I tried to select the secondhighestsalary from the employee table, this was my go, but it returned the SQL statement is not properly ended select salary as secondhighestsalary from employee order by salary desc offset 1 rows fetch next 1 rows…
0
votes
2 answers

How to use top_n for conditional extraction

So I have a column (category) that contains either "Yes" or "No" in my df and in order to create a more balanced sample I want to select the rows with the first 500 cases of "Yes" and the first 500 cases of "No" from my dataset. I've tried this…
user14808367
0
votes
1 answer

Why doesn't rev(factor) work as a way to reverse the wt argument of dplyr::top_n()?

Goal: return the row with thing1=F and thing2=MeFirst Why does this not work? tibble( row = 1:10, thing1 = c(rep("F",5),rep("L",5)), thing2 = c(rep("MeSecond",4),rep("MeFirst",2),rep("MeSecond",4)) ) %>% mutate( thing1 =…
0
votes
1 answer

Top N sorted rows with GROUP BY?

I have the following transaction table: customer_id, category, product_id, score I'm grouping by customer_id and category to create a list of product_id-score map pairs: SELECT s.customer_id, s.category, collect_list(s.pair) FROM …
alhazen
  • 1,907
  • 3
  • 22
  • 43
0
votes
1 answer

execution plan for fetch first rows only

I have a question on fetch first x rows. Does this function execute after all the joins have been completed for all the rows in a table or does it return the result as soon as it hits the number ? eg: Table a has 100k rows table b has 72k rows query…
0
votes
2 answers

Error in Selecting least 3 rows from each group in ms Access - only least 2 rows are getting selected

I have the data containing 2 columns ID_NO and Date_of_arrival. I want to find the least 3 date_of_arrival for each ID in MS-Access. I have written the code and it is working fine for all the ID_NO except "11111-00000-11", wherein it is selecting…
Asmita
  • 25
  • 1
  • 6
0
votes
2 answers

top value dimension based on sum in SQL

i am having an issue with a query to bring back the top type of transaction for each location: my table has location varchar, type varchar, transaction int i've tried the following and get errors: select c.location, c.type, sum(c.transaction) as…
kevlar
  • 1
  • 1