Questions tagged [top-n]
322 questions
0
votes
4 answers
Need help in writing SQL query
I am facing a pecular problem in writing a sql query for below functionality:
Consider below table:
---------------------------------
AccountNumber JobNumber
---------------------------------
1234 1111113
1234 …

Pradeep Simha
- 17,683
- 18
- 56
- 107
0
votes
4 answers
Use of MIN and COUNT
Can you give me an example at use of the min and count at the same query? For example on this table I want to know the lower number of workers with an odd Code (1 with the code 5).
Table Workers
Code
1
2
2
2
…

tomss
- 269
- 4
- 6
- 12
0
votes
2 answers
Returning max value and value prior
I have a query I run to tell me the latest note for active participants:
select notes.applicant_id,
reg.program_code,
reg.last_name,
reg.first_name,
reg.status_cd,
MAX(notes.service_date) as "Last Note"
from reg inner join notes on…

user1466935
- 7
- 1
- 4
0
votes
2 answers
how to get first female of each tool, oracle database
Possible Duplicate:
Oracle SQL - How to Retrieve highest 5 values of a column
I'm writing oracle query but stuck in the following problem
table is like this:
**Tool** **Name** **Gender**
Facebook Alice F
Facebook Alex …

Ivan Li
- 1,850
- 4
- 19
- 23
0
votes
1 answer
Finding the MAX
Possible Duplicate:
Oracle SQL - How to Retrieve highest 5 values of a column
I have a simple question for someone who knows anything about SQL but since i'm very new and although I have tried many different ways, I can never seem to get the…

dan boy
- 89
- 8
0
votes
1 answer
Find the most expensive order
I'm trying to find the most expensive order within my table, and I've achieved this, but I'd like to know how to just return this one particular row. Right now it turns all rows with the most expensive order at the top. I'm not quite sure how to…
user676853
0
votes
3 answers
aggregation subquery with top N
Let's say I have a table called COFFEE showing Bus Stations and all of the coffee shops within 10 blocks of the bus station:
BusStationID| CoffeeShopID | Distance (in city blocks)
1|2103|2
1|2222|2
1|8864|7
1|9920|5
…

Tim
- 8,669
- 31
- 105
- 183
0
votes
3 answers
Selecting top n elements elements in java list of models with criteria
I have a MySQL table as such
id_user id_info
1 45
1 54
1 12
2 16
2 48
3 94
... ...
For all of my users, I want to select n info at random (say, 1), or with a criteria. I know that it is quite intensive in pure MySQL when the table is large (I tried…

Xavier
- 423
- 1
- 4
- 8
0
votes
1 answer
SQL query to get top 10 of a new column generated by SUM
I have a query that looks like so:
SELECT Name, SUM(Price * Quantity) AS Total
FROM Sales
WHERE Date = " + ddItems.SelectedItem + "
GROUP BY Name
How can I show the top 10 totals?

dev6546
- 1,412
- 7
- 21
- 40
-1
votes
1 answer
What "row reduction clauses" does Oracle support? (for Excel Power Query)
I want to add an Oracle table as a data source in Excel 2016 Power Query (via ODBC):
At the bottom of the ODBC dialog, there is an option to specify the "Supported row reduction clauses (optional)":
Question:
What option applies to Oracle…

User1974
- 276
- 1
- 17
- 63
-1
votes
3 answers
Finding one value in relation to the value of another column
I've got a table that looks a bit like this
What I want to do is find the pressure value of the earliest Start_Time
So in this case I want the value "5"
How can I do this? I'm not sure of how to relate 2 values this way

Sam
- 627
- 2
- 13
-1
votes
2 answers
Need to get first successful completion date from completions
My data looks like this:
StuId StuName Exam Attempt Score
1 Sam Eng 1 45
1 Sam Eng 2 58
1 Sam Eng 3 63
2 Mat Eng 1 65
2 Mat Eng 2 75
The student has passed if he has gotten…

twitter investor
- 17
- 3
-1
votes
1 answer
Excel find top 10 values on each column
Let's say I have a table: the columns correspond to years (such as 1999, 2000, ..., 2020) and the rows are countries.
How can I make Excel display only the top 10 values of each column and set other countries values =0 ?

ratsafalig
- 442
- 5
- 21
-1
votes
1 answer
need a sql to get the tourist who paid maximum amount in single booking
i have two tables tourist(touristid,touristname,city),
bookings(bookingid,touristid,bookingamount)
i need the touristid,touristname,city of tourist who have paid the maximum amount in a single booking

bruno felix
- 1
- 1
-1
votes
3 answers
Get the name of the employee with the second highest salary
I have to get the name of employee with the second highest salary the table name from where I am fetching is emp. I know the query for second highest salary which is
select max(sal)
from emp
where sal < (select max(sal) from emp)
it works and it…

Adnan Ahmed
- 29
- 9