mySQL 查询:SUM/MAX 问题

发布于 2024-10-21 21:46:20 字数 472 浏览 1 评论 0原文

我对此非常陌生,并且在查询中遇到 SUM 和 MAX 问题:

SELECT Score.performerId, Performer.performerName, 
 Performer.countrycode, Country.countryName, Event.eventName, Score.points
FROM Score, Performer, Country,  Event
WHERE points = (SELECT MAX(points) FROM Score 
  WHERE roundName = 'Final') 
AND roundName = 'Final'
AND Score.performerId=Performer.performerId
AND Performer.countryCode=Country.countryCode
AND Score.eventId=Event.eventId

我将非常感谢任何帮助。

I am very new to this and having problems with the SUM and MAX in my query:

SELECT Score.performerId, Performer.performerName, 
 Performer.countrycode, Country.countryName, Event.eventName, Score.points
FROM Score, Performer, Country,  Event
WHERE points = (SELECT MAX(points) FROM Score 
  WHERE roundName = 'Final') 
AND roundName = 'Final'
AND Score.performerId=Performer.performerId
AND Performer.countryCode=Country.countryCode
AND Score.eventId=Event.eventId

I will greatly appreciate any help.

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

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

发布评论

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

评论(1

十年九夏 2024-10-28 21:46:20
SELECT
    Score.performerId, Performer.performerName, 
    Performer.countrycode, Country.countryName, Event.eventName, Score.points
FROM Score, Performer, Country,  Event,
    (
    SELECT Performer.PerformerId, SUM(score.Points) TotalScore
    FROM Score, Performer, Country,  Event
    WHERE roundName = 'Final'
    AND Score.performerId=Performer.performerId
    AND Performer.countryCode=Country.countryCode
    AND Score.eventId=Event.eventId
    group by Performer.PerformerId
    order by TotalScore Desc
    LIMIT 1
    ) MaxScore
WHERE roundName = 'Final'
AND Score.performerId=Performer.performerId
AND Performer.countryCode=Country.countryCode
AND Score.eventId=Event.eventId
AND Performer.PerformerId=MaxScore.PerformerId

我有点懒于转换为 ANSI 样式连接,但您应该开始考虑使用它们而不是逗号符号。

SELECT
    Score.performerId, Performer.performerName, 
    Performer.countrycode, Country.countryName, Event.eventName, Score.points
FROM Score, Performer, Country,  Event,
    (
    SELECT Performer.PerformerId, SUM(score.Points) TotalScore
    FROM Score, Performer, Country,  Event
    WHERE roundName = 'Final'
    AND Score.performerId=Performer.performerId
    AND Performer.countryCode=Country.countryCode
    AND Score.eventId=Event.eventId
    group by Performer.PerformerId
    order by TotalScore Desc
    LIMIT 1
    ) MaxScore
WHERE roundName = 'Final'
AND Score.performerId=Performer.performerId
AND Performer.countryCode=Country.countryCode
AND Score.eventId=Event.eventId
AND Performer.PerformerId=MaxScore.PerformerId

I'm a bit lazy to convert to ANSI style joins but you should start looking at using them in preference to the comma notation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文