Selecting Item that has Max of one but Min of another in SQL [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a table that lists players on a team, the number of years on the team, and the number of points scored. What I'm trying to do is return the person that has the most number of points scored and the least number of years on the team. This is what I've done:
SELECT player
FROM team
GROUP BY player
HAVING MAX(points) and MIN(years);
Example of a table and expected output:
player | years | points
-------+-------+---------
p1 | 2 | 200
p2 | 5 | 10
p3 | 1 | 500
From this I expect to get back p3 since they have the min for years and the max for points.

This will give you players with max points, and also players with min years:
SELECT player, points, years
FROM team
where points = (select max(points) from team)
or years = (select min(years) from team)

Related

Trying to get count of episodes in a series [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
Improve this question
I want to figure out total number of episodes in a series. Lets say this series has 3 seasons, 10 episodes each season. I want a count that would provide the value of 30 (30 total episodes). The kicker is that this series has aired say in 2 different countries, some countries got only 1 season, and the other got 3. I still want to only pull the 30 unique total episode count.
The series has its own ID Each season has its own ID Each episode has its own ID Each country has its own ID
How can I accomplish this?
I am looking to get a total count of 30.
Ive tried various statements...
(CONCAT(seasonid,'_', episodeid, '_',seriesid,'_', countryid)) as a
count(distinct(CONCAT(seasonid,'_', episodeid, '_',seriesid,'_', countryid))) + sum(case when a is null then 0 else 1 end) as count
sum(case when (count(distinct (CONCAT(seasonid,'_', episodeid, '_',seriesid)) )) is not null then 1 else 0 end) as count
count( distinct(CONCAT(seriesid,'_', episodeid ))) as count

Get most common value in column [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have next table:
id value
1 2
2 4
3 2
4 2
5 3
How I can get most common (common means that the count of 2 is 3, count of 4 is 1 and count of 3 is 1, so common is 2) 'value'? in this case it is '2'?
you can use group by
select value
from the_table
group by value
order by count(*) desc
limit 1

Write an Sql query to display the top selling model of each manufacturer for each year [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Given below is the table of Car sales (of all models from different manufacturers) . ( only few rows are shown)
Date Name Model Units_sold
Dec-2020 Audi A4 300
Dec-2020 BMW 3Series 164
Jan-2020 Maruti Alto 33118
Jan-2020 Toyota Fortuner 1103
Feb-2020 skoda Superb 391
On SQL Server we can try:
SELECT TOP 1 WITH TIES Date, Name, Model, Units_sold
FROM yourTable
ORDER BY
ROW_NUMBER() OVER (PARTITION BY YEAR(Date), Name ORDER BY Units_sold DESC);

Query to find man of the tournament [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a table which has the below data:
PLAYER RUN
-----------------
Kohli 100
Kohli 200
Sachin 200
Yuvi 300
Yuvi 300
Yuvi 300
I need to return the Player's name who scored the maximum number of runs.
How can I achieve this by a SQL query ? In this case the query should return "Yuvi" .
Could you please use the query given below
SELECT TOP 1 PLAYER, MAX(RUN) AS MAXRUN FROM <TABLE> GROUP BY PLAYER ORDER BY MAXRUN DESC;
select player from (select player , sum(runs) from test group by player,runs order by sum(sal) desc) where rownum=1;
You should use Max function in the column RUN. The query will be,
Select PLAYER, MAX(RUN) from TABLE;

Assign values to sorted result in SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have got table like below after sorting in SQL:
M_ID
-----
2013/01
2013/02
2013/03
2013/04
2013/05
2013/06
Now I want to assign each entries a particular value like below
M_ID Days
--------------
2013/01 20
2013/02 30
2013/03 40
2013/04 50
2013/05 60
2013/06 70
So, can you please let me know how to do that in SQL Query?
Do you mean something like this (presuming sql-server)?
SELECT M_ID,
Days = (ROW_NUMBER()OVER(ORDER BY M_ID) + 1) * 10
FROM dbo.TableName
Demo