FAQ Database Discussion Community


Subquery with Sum of top X rows

sql,sql-server,subquery,top-n
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, (Select top 1 r2.points from Results r2 where r2.season=r.Season...

Get the first 10 rows for each group

sql,oracle,select,oracle11g,top-n
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, nbCommands) But I only want 10 products for each customer, the ones he ordered the most and...

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

python,sorting,top-n
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 = {c:max(d[c][-3:]) for c...

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

sql,database,oracle,odbc,top-n
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 Oracle driver ONLY connect to Oracle servers,...