Love__Tay 2022-10-26 10:52 采纳率: 68.8%
浏览 44
已结题

mysql 对计数结果重命名

leecode做数据库题178. 分数排名时遇到的疑问
# Write your MySQL query statement below
SELECT score, COUNT(a_score)+1 
FROM
(
SELECT score,id,tb1.a_score,tb1.b_id,tb1.b_score
FROM Scores
LEFT JOIN
(SELECT DISTINCT a.score AS a_score,b.id AS b_id,b.score AS b_score
FROM Scores AS a,Scores AS b
WHERE a.score > b.score) AS tb1
ON tb1.b_id = Scores.id
) AS tb2
GROUP BY tb2.id
-- HAVING tb2.a_score != 'NULL'
ORDER BY score DESC


报错截图

img

尝试对字段重命名但报错了,网上也没找到类似的问题
SELECT score, COUNT(a_score)+1 AS rank

img

是因为类似count()+1这种不能进行字段重命名吗?
  • 写回答

2条回答 默认 最新

  • 往事随风云渐起 2022-10-26 11:19
    关注
    
    # Write your MySQL query statement below
    SELECT score, COUNT(a_score)+1 as `rank`
    FROM
    (
    SELECT score,id,tb1.a_score,tb1.b_id,tb1.b_score
    FROM Scores
    LEFT JOIN
    (SELECT DISTINCT a.score AS a_score,b.id AS b_id,b.score AS b_score
    FROM Scores AS a,Scores AS b
    WHERE a.score > b.score) AS tb1
    ON tb1.b_id = Scores.id
    ) AS tb2
    GROUP BY tb2.id
    -- HAVING tb2.a_score != 'NULL'
    ORDER BY score DESC
     
     
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 11月3日
  • 已采纳回答 10月26日
  • 创建了问题 10月26日

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。