简体   繁体   English

SQL 编写查询以满足两个要求 [关闭]

[英]SQL writing query to fulfill two requirements [closed]

I am doing a practice problem where I need to write a query that shows all top 100 songs from 1985 to 1990. I tried the following code:我正在做一个练习题,我需要编写一个查询,显示从 1985 年到 1990 年的所有前 100 首歌曲。我尝试了以下代码:

SELECT * FROM billboard.chart 
WHERE year BETWEEN 1985 AND 1990
LIMIT 100 

But it seems like the table contains a tie, so that only gives me until rank 96. I tried using two WHERE clauses, but this gives me an error.但似乎该表包含一个平局,所以只给我直到排名 96。我尝试使用两个 WHERE 子句,但这给了我一个错误。

SELECT * FROM billboard.chart 
WHERE year BETWEEN 1985 AND 1990
WHERE year_rank BETWEEN 1 AND 100 

How should I go about extracting both certain time period and certain ranks?关于提取特定时间段和特定等级,我应该如何 go ?

This will give you the expected output.这将为您提供预期的 output。

SELECT * FROM billboard.chart 
WHERE year BETWEEN 1985 AND 1990
AND year_rank BETWEEN 1 AND 100 

You can explore default RANK or DENSE_RANK function within MySQL, it gives you more flexibility on how to handle ties.您可以在 MySQL 中探索默认RANKDENSE_RANK function,它为您提供了更多处理平局的灵活性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM