Questions tagged [top-n]
322 questions
0
votes
1 answer
SQL MAX statement
I'm going to do a better job describing my issue and I want to include my data.
I have data I need out of 6 tables:
Students s
StoredGrades sg
Test t
TestScores ts
StudentTest st
StudentTestScore sts
Here's what I'm trying do. I need a report that I…

jlinds
- 1
- 1
0
votes
7 answers
how to get maximum of two records for each employee
I have a table in the database with records as shown below :
Id | EmpName | LeaveDate | createdDate
1 | Govind | 2014-04-02 00:00:00.000 | 2014-04-02
2 | Aravind | 2014-04-03 00:00:00.000 | 2014-04-05
3 | Govind | 2014-04-04…

Thadeuse
- 1,713
- 2
- 12
- 19
0
votes
1 answer
How can I get a various number of rows while limiting the number of different ids in one SQL query?
Let's say I have a table with two ids, series_id and match_id. The series_id can be repeated, but match_ids are unique. In addition, the number of possible match_ids per series can vary from 1 to 5. I want to select the top 10 series and all the…

avbor
- 43
- 7
0
votes
3 answers
Get top-6 elements, subject to the condition that element >= 3
I'm trying to make a list of 11 elements
I want to pop out the maximum element only from l[0] to l[5]. under one of the two conditions:
l[5] >= 3 or l[5] is no longer exist or None.
l = [2,8,6,2,8,7,9,8,6,7,4]
max = 0
maxIndex = 0
while (l[5] >= 3…

Xi N
- 1
- 2
0
votes
2 answers
Count Query Reciepe/Ingredients
basically I've been working on an SQL question which is asking to display each ingredient along with the total number of recipes it's included in. It also must only include the ingredients that occur more than 10 times and descending order of…

saz
- 1
- 3
0
votes
1 answer
The average duration of first 80% records
For example I have the following list of calls:
Call#1 - duration 30 min
Call#2 - duration 43 min
Call#3 - duration 26 min
Call#4 - duration 35 min
Call#5 - duration 39 min
1) I need the SQL query retrieving the average duration of first 80% of…

sbrbot
- 6,169
- 6
- 43
- 74
0
votes
1 answer
Get sum of multiplication of two columns of two tables
I have product table like this
PRODUCT_ID PACK_SIZE PACK_PRIZE
3000 5 2.5
3001 5 2.5
3002 5 2.5
3003 5 2.5
Order table
order_id client_id
75001 1024
75002 1033
75003 …

ChathurawinD
- 756
- 1
- 13
- 35
0
votes
4 answers
how to display only 20 items of the result in oracle sql?
Is it possible to display only 20 items of the whole result?
I know of a query "rownum>=20" but that only makes the sql check only the first 20 rows in the table.
But i want the sql to check my whole table and display only the highest 20…

SuperCoder
- 262
- 1
- 3
- 13
0
votes
2 answers
How to fetch the top-n using inline view while performing a join with tables in main query in Oracle / SQL?
It seems like a really simple query but I must be missing something obvious. I am assuming that this scenario is pretty common.
I have a table which stores the products and another table that stores the transactions. The transaction table has…

sohail
- 589
- 1
- 11
- 26
0
votes
1 answer
Apache Hive Query HiveQL
I am learning Hive and wanted to write an optimized HiveQL/SQL query
My table looks like this:
CREATE TABLE sales (dealer VARCHAR(25), make VARCHAR(25), type VARCHAR(25), day INT);
INSERT INTO sales (dealer, make, type, day) VALUES
("Xyz",…

foobarometer
- 751
- 1
- 9
- 20
0
votes
1 answer
Mongo query against subdocument with a top N
I've got the following data in a user collection in MongoDB:
{
"_id" : ObjectId("53807beee4b0d2b25747df7e"),
"allowedAppIds" : [
{
"appId" : "534c8d2ce4b024b1f08e16e6",
"createdDate" :…

heetrie
- 3
- 1
0
votes
3 answers
Trying to figure out how to join these queries
I have a table named grades. A column named Students, Practical, Written. I am trying to figure out the top 5 students by total score on the test. Here are the queries that I have not sure how to join them correctly. I am using oracle 11g.
This…

user3794621
- 19
- 7
0
votes
4 answers
Trying to figure out top 5 land areas of the 50 states in the U.S
I have a table created. With one column named states and another column called land area. I am using oracle 11g. I have looked at various questions on here and cannot find a solution. Here is what I have tried so far:
SELECT LandAreas, State
FROM (…

user3794621
- 19
- 7
0
votes
1 answer
Unable to get only first occurrence of each job
I am trying to query some jobs from a repo, however I only need the job with the latest start time. I have tried using ROW_NUMBER for this and select only row number 1 for each job, however it doesn't seem to fall through:
SELECT…

rolandvarga
- 126
- 1
- 10
0
votes
1 answer
Count(*) againt Top 1 in SQL Server
We work with tables with a lot of records. Anyone knows if is better to make a Count(*) or a Top 1 to know if a specific record exists or a group of records match some conditions. Also this type of sentence lock the table or I need to specify no…

David Escudero
- 13
- 1
- 3