Questions tagged [top-n]

322 questions
1
vote
2 answers

ORA-00936: expression absente

Can you help me know what maybe the error in my sql?ORA-00936: I'm having missing expressionerror but I cannot find the error. select p.nompr from produit p where p.idpr=(select o.idpr from objet o,enchere e where…
user3093583
  • 101
  • 1
  • 2
  • 7
1
vote
1 answer

Top N by Total Sales in Year X Filter Tableau

How to place a filter in my worksheet that filters a category by top sales in a certain year while still showing all years of data for that category. Does anyone have an idea how to do this?
1
vote
2 answers

Performance issue on selecting n newest rows in subselect

I have a database with courses. Each course contains a set of nodes, and some nodes contains a set of answers from students. The Answer table looks (simplified) like this: Answer id | courseId | nodeId | …
1
vote
1 answer

DevForce 2010 Top n query

I'm wanting to remove duplicate records from a table that has over 2 million rows. I have an IEntityQuery that does the grouping and counting and returning where count() > 1. The problem is this query also could return over a million rows. I…
1
vote
1 answer

Get the first 10 rows for each group

I have three tables: Customer(IdCustomer, Name) Product(IdProduct, Product) Order(IdProduct, IdCustomer, nbOrders) So the Order table stores how many times a customer has ordered a product. I need a view like this: TopOrder(Name, Product,…
1
vote
4 answers

Average of top 3 values within a specific pivot field

I have a table in which in one column I have values that are assigned to special models of hardware. The table looks like this: We need to find an average of three of the highest numbers for each model in that table, for example: We have a model…
NakedCat
  • 852
  • 1
  • 11
  • 40
1
vote
2 answers

How to determine what type of database - Old legacy corporate database

I have access to a legacy corporate database that I can connect to via Microsoft's ODBC for Oracle driver through Visual Studio 2010. Can I query the database to determine what type and version the database is? Also, will the Microsoft ODBC for…
masospaghetti
  • 348
  • 5
  • 12
1
vote
4 answers

Sorting per-user list by average value of top-3 entries

I have some data which is a list of scores for each of various users. The following code finds the maximum value of the last three scores for the user (sorted so the user with the lowest score is shown first), and print that out: dlist =…
DasKapital
  • 73
  • 7
1
vote
1 answer

Subquery with Sum of top X rows

I am trying to get the top 5 results for each person from a table. I am able to get the top result for them however I want the sum of the top 5. Select Distinct r.LastName, r.FirstName , r.Class, r.BibNum, …
BlueBird
  • 1,406
  • 4
  • 24
  • 35
1
vote
1 answer

MS-Access SELECT TOP N subquery SQL

have attempted this query multiple times, feel like I am just missing something simple. this example: aggregation subquery with top N is close to what I am looking to accomplish, however rather than averaging the distance I only want to return the…
aaronlee
  • 11
  • 3
1
vote
1 answer

MySQL fetch total 20 rows but only 10 rows of each unique id

I have a little problem here that I'll try to explain. I want to fetch the latest (highest id) maximum 10 rows (can exist more/less than 10) per each unique id in a table. So if I'm interested in knowing the latest 10 rows from id "1" and "2" I…
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
1
vote
1 answer

Select a name in sql

I selecting the category name from a category table using the below query select Category.Name from Product inner join ProductCategory on ProductCategory.PID=Product.PID inner join ProductMaterial on ProductMaterial.PID=Product.PID …
Arun
  • 1,402
  • 10
  • 32
  • 59
1
vote
2 answers

How to optimize a select top N Query

I have a very large table, consisting of 40 million rows, in a SQL Server 2008 Database. CREATE TABLE [dbo].[myTable]( [ID] [bigint] NOT NULL, [CONTRACT_NUMBER] [varchar](50) NULL, [CUSTOMER_NAME] [varchar](200) NULL, …
1
vote
3 answers

need oracle query

I am practising Oracle Subqueries.. (I am new to Oracle.) Question: Find the Highest Earning Employee in each Department? My query below works (BUT I feel its not that good, even though I get the correct result ) select e.deptid, e.name, e.salary…
Irwin
  • 105
  • 1
  • 2
  • 7
1
vote
2 answers

Find top 3 users per location

I am fairly new to SQL, working on some practice problems. I have a sample Twitter database and I am trying to find the top 3 users in each location based on number of followers. Here are the tables I am using: id_follower_location id …
user908015