显示最受欢迎的男性和女性名字

发布于 2025-01-12 23:18:19 字数 396 浏览 4 评论 0原文

从名为 BabyName 的数据库中显示 1983 年最受欢迎的男性和女性名字

SELECT COUNT(name) "Most Popular M/F Names from 1983", name  
FROM BabyName 
GROUP BY name 
ORDER BY year = '1983' AND COUNT(name) DESC
LIMIT 50

这是试图从 1983 年提取最受欢迎的男性和女性名字。这使用了名为 BabyName 的数据库及其一个相当大的数据库。 这是我想到的唯一方法,但我也觉得它是错误的,因为它要求最受欢迎的女性和男性名字。关于如何处理这个问题有什么建议吗?我无法显示数据库信息,因为它相当大,但它包含姓名、性别、出生年份和来自哪里。

Display the most popular male and female names from the year 1983 from the database named BabyName

SELECT COUNT(name) "Most Popular M/F Names from 1983", name  
FROM BabyName 
GROUP BY name 
ORDER BY year = '1983' AND COUNT(name) DESC
LIMIT 50

This is trying to pull the most popular male and female names from the year 1983. This is using a database called babyname and its a fairly large database.
This is the only way I figured out but I also feel like its wrong because its asking for the most popular female and male names. Any suggestions on how you might approach this? I can't show the DB information because its fairly large but it contains the name, gender, year they were born and the place they are from.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尛丟丟 2025-01-19 23:18:19

在 MariaDB 中,您可以使用窗口函数:

with cte as (
    select
        gender,
        name,
        count(*) as c,
        dense_rank() over (partition by gender order by count(*) desc) as dr
    from babyname
    where year = 1983
    group by gender, name
)
select *
from cte
where dr <= 5
order by gender, c desc

In MariaDB you can use window functions:

with cte as (
    select
        gender,
        name,
        count(*) as c,
        dense_rank() over (partition by gender order by count(*) desc) as dr
    from babyname
    where year = 1983
    group by gender, name
)
select *
from cte
where dr <= 5
order by gender, c desc
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文